How to fix npm peer dependency issue? - javascript

I have a package.json that has the following modules that are conflicting:
react-router which needs react 0.13.x
redbox-react which needs react#>=0.13.2 || ^0.14.0-rc1
I just did an npm install react and it installed react#0.14
I am trying to install react-bootstrap which needs react#>=0.14.0.
I have been a few solutions:
delete node_modules from all the node_modules of dependencies every time I update
delete and reinstall all modules every time you face an issue
upgrade to npm 3.x which is still pre-release and
What is a good way of fixing these issues without having to do 1 or 2 which is npm version agnostic.
P.S.: All the modules referred to here have been installed locally.

Ensure you have the latest version of react-router (currently 1.0.0-rc3).
The react module is only listed as a dev dependency, and the requested version is 0.14.0 so there shouldn't be any issues.

Related

Does npm/yarn install devDependencies by default?

I'm working on private library of react components. I've already setup the whole workflow etc. but I'm not sure about one thing.
In my library I have some packages listed as peerDependencies which have to be peer ones (for example react, cuz only one instance of react can be installed at once, otherwise everything breaks). But if I'd like to setup some tests in my library I need react installed there as devDependency.
So I have to install react as peer and dev in library. And what happens when I publish this package to npm register? devDependencies are excluded here?
Thanks!
If you need it in production, add it to peerDependencies. Otherwise, leave it in devDependencies. When someone installs your library, dev dependencies won't be installed, and peer dependencies should already be installed.
If you create a node package, and you have some dev dependencies, npm wont count them for the publish. That's why it's called devDependencies. It's not under the production code.
I know you have to specify when installing an npm package --save-dev so it saves dependencies onto your json file.

NPM peer dependencies issue while building vis-timeline locally

I am using vis-timelime in one of my projects. I have done some changes in vis-timeline, then locally build it and using it as dependency in my project. While doing so, vis-timeline is getting installed properly but i believe the peer dependencies of vis-timeline are not coming. Do note that I'm using npm version - 7.6.3.
cd vis-timeline;
//added some console logs in few files
npm install;
npm run build;
Then in my project-
cd my-app
npm install local-path-to-my-vis-timeline
Running above commands install the vis-timeline in node_modules of my-app. However, other peer dependencies of vis-timeline like vis-data, etc. do not come automatically. Since I am using npm version 7.6.3, wasn't it supposed to happen automatically?? If not, any graceful solution to this?
Or let me know of any other better way to locally do changes in vis-timeline library and use it in my local project for debugging.
Sounds like an issue with npm. This post has a list of solutions that might work.
Otherwise, maybe try using yarn instead of npm?

Uninstalling react app from scratch (Linux)

I am in the process of creating a React app (using Linux-Ubuntu, npm 3.5.2, node v8.10.0, with npx). I used the following-
npx create-react-app my-app
But to start the app:
npx start
I got a bit of errors (shown below)
There might be a problem with the project dependency tree.
It is likely not a bug in Create React App, but something you need to fix locally.
The react-scripts package provided by Create React App requires a dependency:
"eslint": "^6.6.0"
Don't try to install it manually: your package manager does it automatically.
However, a different version of eslint was detected higher up in the tree:
/home/dirsomename/Projects/node_modules/eslint (version: 5.16.0)
Manually installing incompatible versions is known to cause hard-to-debug issues.
If you would prefer to ignore this check, add SKIP_PREFLIGHT_CHECK=true to an .env file in your project.
That will permanently disable this message but you might encounter other issues.
To fix the dependency tree, try following the steps below in the exact order:
1. Delete package-lock.json (not package.json!) and/or yarn.lock in your project folder.
2. Delete node_modules in your project folder.
3. Remove "eslint" from dependencies and/or devDependencies in the package.json file in your project folder.
4. Run npm install or yarn, depending on the package manager you use.
In most cases, this should be enough to fix the problem.
Well, it did not fix the problem even after following the steps above.
So, my goal now is to retrace my steps and to uninstall the complete React app from scratch.
How do I go about doing that?

How does yarn work when it encounters ^ (caret)?

How does yarn work when it encounter a ^ (caret) in package.json dependencies?
Let's say I have react: ^16.0.0 and when I yarn install, it will create a lock on that version (16.0.0).
Now sometime later when react 16.1.0 is released, and I yarn install again with the lock file, will yarn upgrade it to that version or follow what is in the lock file which is 16.0.0?
Thanks.
yarn install will install the exact version in the lockfile. That's the great benefit of a lockfile, everyone working on your project gets the exact same version of the package regardless of when the do yarn install. (e.g. I do yarn install today, when 16.0.0 is the current version, but you do yarn install tomorrow when 16.1.0 is the current version. We'll still both get 16.0.0 because that's what our lockfile says we should get. Our development environments are exactly the same, which is what we want. Likewise if we deploy in 2 weeks when 16.2.0 is the current version, 16.0.0 will get deployed; thus our dev and prod environments are exactly the same, too)
If 16.1.0 is released and you want to update your project to use it, use yarn upgrade. Note that you can upgrade all of your packages, or just one specific package, as well as update to the latest version of a package or a specific version of a package. https://yarnpkg.com/lang/en/docs/cli/upgrade/
Version Control Your package.json and yarn.lock
By adding these two files to version control, you'll easily be able to revert your project to a specific point in time in regards to your packages.
The selected answer is wrong.
caret means following
^3.1.4 will allow a version range from >=3.1.4 <4.0.0

Error: Module did not self-register.

Server: Ubuntu server 14.04
Node: v4.2.6 LTS
npm: 1.3.10
I pullled my colleage's work from git remote. He made the node_modules as .gitignore. So I have to npm install the modules.
But after a successful install of npm. when I try to start the project using mocha. It remind me of a module didn't self-register
The error comes from the module of Bcrypt.
at bindings (/base_dir/node_modules/bcrypt/node_modules/bindings/bindings.js:76:44)
I don't want to downgrade my node to 0.10, because, I can't use JS promise in that version. Somehow, JS promise is a must in my work
This problem happens mostly because you copied/cloned the repository from somewhere else, but some modules for nodeJS should be installed/registered locally on your machine, during which the happens the build process(maybe some native language like C).
and be noted that the node_modules folder should not be staged for versioning. and should be ignored by versioning tool. and the one who is trying to clone this package should build / install firstly.
I find the answer to this problem.
But plz don't devoted this just because you want.
I upgrade the NPM using
npm install npm -g.
after that, delete the node_modules folder,
then,
npm install
Everything will be good.
I had this issue while setting up my Cypress project.
After trying to delete and then reinstalling all the node-modules and upgrading everything I found out the issue was caused because Cypress uses node from its bundle version by default (which was version 8.0 in my case) , whilst the package I wanted to use required the node version to be 10 or higher.
I did have node 12.0 installed on my machine but since cypress was not using that I had to add the line shown below in the settings file (cypress.json) to set the value for 'nodeVersion' to 'system', this way you are telling cypress explicitly to use the node version installed on your machine.
Add this line to your settings file:
**"nodeVersion": "system"**

Categories

Resources