npm list does not show installed package - node.js

I'm having trouble understanding npm. I have a node.js project with react, but I am not able to find the latter with npm list.
I certainly have it installed, because my project using react works.
I also have it in my package.json file under "dependencies":
"dependencies": {
"react": "^16.4.1"
}
Also, if I search for react on my drive, I find the module for it in my project folder:
user/Dev/project/node_modules/react
However, if I do npm list react, I get nothing:
me ~/D/project> npm list react
project#0.1.0 /Users/me/Dev/project
└── (empty)
Even if I do npm install or even specifically npm install react --save, no change.
Nor is the package listed with npm list or npm list -g (with or without --depth=0), except I get further indications that npm does not 'see' the react module:
UNMET PEER DEPENDENCY react#16.4.1
I'm using npm v5.6.0.
Any ideas?

I fixed this by running npm update command. (If that doesn't work try to delete node_modules and package-lock.json prior to running npm_update)

Related

Get " a different version of webpack was detected higher up in the tree" error in CRA react app

I am getting this error while running npm start on my CRA app. I tried uninstalling and installing webpack. Only thing that works is,
creating a ".env" file at the root with SKIP_PREFLIGHT_CHECK=true.
`
hello#0.1.0 start C:\Users\USER\Desktop\MyReact\REACT_HOOKS\hello
react-scripts start
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:
"webpack": "4.42.0"
Don't try to install it manually: your package manager
does it automatically.
However, a different version of webpack was detected higher up in the tree:
C:\Users\USER\node_modules\webpack (version: 4.43.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:
Delete package-lock.json (not package.json!) and/or yarn.lock in your project folder.
Delete node_modules in your project folder.
Remove "webpack" from dependencies and/or devDependencies in the package.json file in your project folder.
Run npm install or yarn, depending on the package
manager you use.
In most cases, this should be enough to fix the problem.
If this has not helped, there are a few other things you can try:
If you used npm, install yarn (http://yarnpkg.com/) and repeat the above steps with it instead.
This may help because npm has known issues with package hoisting which may get resolved in future versions.
Check if C:\Users\USER\node_modules\webpack is outside your project directory.
For example, you might have accidentally installed something in your home folder.
Try running npm ls webpack in your project folder. This will tell you which other package (apart from the expected react-scripts) installed webpack.
If nothing else helps, add SKIP_PREFLIGHT_CHECK=true to an .env file in your project.
That would permanently disable this preflight check in
case you want to proceed anyway.
P.S. We know this message is long but please read the steps above 🙂 We hope you find them helpful!
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! hello#0.1.0 start: react-scripts start
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the hello#0.1.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
`
Ok, I ran npm uninstall -g webpack it didn't do anything.
then I ran both
npm uninstall -g webpack
npm uninstall webpack
and it's not showing the error anymore.
so apparently
npm uninstall webpack
worked.
Probably the issue was caused by a manual download of webpack.
I ran npm uninstall webpack, delete package.lock.json, and then run yarn.
If you prefer npm, then instead of running yarn , you run npm install.
This will re-install webpack the right way in the dependency tree.

npm start does not work. I've tried everything. I'm confused

So whenever I run npm start in my React project it gives me this error:
myapp#0.1.0 start C:\Users\AyaLe\Desktop\React\myapp react-scripts
start
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:
"webpack": "4.19.1"
Don't try to install it manually: your package manager does it
automatically. However, a different version of webpack was detected
higher up in the tree:
C:\Users\AyaLe\node_modules\webpack (version: 3.10.0)
Manually installing incompatible versions is known to cause
hard-to-debug issues.
If 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:
Delete package-lock.json (not package.json!) and/or yarn.lock in your project folder.
Delete node_modules in your project folder.
Remove "webpack" from dependencies and/or devDependencies in the package.json file in your project folder.
Run npm install or yarn, depending on the package manager you use.
In most cases, this should be enough to fix the problem. If this has
not helped, there are a few other things you can try:
If you used npm, install yarn (http://yarnpkg.com/) and repeat the above steps with it instead.
This may help because npm has known issues with package hoisting which may get resolved in future versions.
Check if C:\Users\AyaLe\node_modules\webpack is outside your project directory.
For example, you might have accidentally installed something in your home folder.
Try running npm ls webpack in your project folder.
This will tell you which other package (apart from the expected react-scripts) installed webpack.
If nothing else helps, add SKIP_PREFLIGHT_CHECK=true to an .env file
in your project. That would permanently disable this preflight check
in case you want to proceed anyway.
P.S. We know this message is long but please read the steps above :-)
We hope you find them helpful!
npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! myapp#0.1.0 start:
react-scripts start npm ERR! Exit status 1 npm ERR! npm ERR! Failed
at the myapp#0.1.0 start script. npm ERR! This is probably not a
problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in: npm ERR!
C:\Users\AyaLe\AppData\Roaming\npm-cache_logs\2018-12-02T10_15_24_630Z-debug.log
Also whenever I try to install webpack-cli whenever it asks me to, it gives me another error
It looks like you have "webpack": "3.10.0" installed globally, but you need to have "webpack": "4.19.1". This is causing a conflict.
You need to do the following:
1. $npm uninstall -g webpack
2. $npm install -g webpack#4.19.1
This should solve the issue.
Alternatively, you can try deleting the node_modules folder or specifically the webpack folder in node_modules at the location:
C:\Users\AyaLe\node_modules\webpack (version: 3.10.0)
It seems that you have an incorrect version of 'webpack' installed. Check your package.json file to ensure that you have the correct 'webpack' version.
The file should look like something this :
{
... ,
"dependencies" : {
...,
"webpack" : "<version number>"
}
}
Ensure that the version number is exactly 4.19.1. This will ensure that you install the specific version of webback.
Once you change/update your package.json, try deleting node_modules/ directory and then running npm install in the same directory as your package.json is.

Versions of npm packages

I installed Express and the package.json shows me "express": "^4.14.0". But when i do npm express -v via console inside my project, it gives me 3.8.8. Can somebody explain, where the different versions come from and how I can fix this?
inside your project run npm install and
then run npm list express to see the version inside your project.
run npm -g list express to check if it may have been installed globally.

Peer dependency issue in npm Node modules

I have run into some issues in installing the grunt related node module dependencies for my project,
I want to install the selected dependencies using one command, so I used below,
npm install grunt grunt-contrib-jshint grunt-cli grunt-contrib-watch grunt-exec grunt-contrib-symlink grunt-contrib-clean grunt-contrib-copy grunt-text-replace grunt-git --save-dev
Got error like 'grunt-exec#0.4.6 requires a peer of grunt#~0.4 but none was installed.'
So as per the feedback from googling, found we can hardcode the dependency version like below fix,
npm install grunt#~0.4 grunt-contrib-jshint grunt-cli grunt-contrib-watch grunt-exec grunt-contrib-symlink grunt-contrib-clean grunt-contrib-copy grunt-text-replace grunt-git --save-dev
It has temporarily fixed the issue for sometime but now I get an error like
'grunt-git#1.0.0 requires a peer of grunt#~1.0.1 but none was installed.'
So it seems that the grunt plugins needs different version of same dependency - grunt(in my case). Installing the plugins one by one instead of a cluster also wont resolve the issue
Update
Since people want to take points away from this answer w/o reading the comments to see that a solution was found, here's what we arrived at:
An instance like this, you should review the previously released versions for grunt-git, find an older version that meets your reqs (v0.3.8) and double check if the features you want to use with the plugin are available or not. If it is, try npm install grunt-git#0.3.8 --save-dev. Releases can be found here.
Original Solution
First you'll want to initialize your project by creating a package.json file by running the command npm init. You'll be prompted to answer several questions, you can change the default values if you like.
Once the project has been initialized, install the dependencies one at a time & include the flag --save or --save-dev. This will add the dependency to the package.json manifest. Example: npm install grunt-contrib-jshint --save-dev
Once you have all of your dependencies listed in your package.json file, you can then achieve a one-command install using npm install.
The NPM registry has a very detailed article on using package.json if you'd like to learn more.
install grunt with the global flag
npm install -g grunt
I have fixed my issue using the suggestions from theaccordance.
Only the recent version of grunt-git(1.0.0) was having the dependency issue, so I am installing the previous version 0.3.7 which doesn't require a particular version of grunt.
npm install grunt#0.4.5 grunt-contrib-jshint grunt-cli grunt-contrib-watch grunt-exec grunt-contrib-symlink grunt-contrib-clean grunt-contrib-copy grunt-text-replace grunt-git#0.3.7 --save-dev
I encountered a similar issue today when trying to install grunt-exec.
npm ERR! peerinvalid The package grunt#1.0.1 does not satisfy its siblings' peerDependencies requirements!
npm ERR! peerinvalid Peer grunt-exec#0.4.6 wants grunt#~0.4
From some clues in this thread I fixed it by...
npm uninstall grunt
at the root folder of my project, and I edited package.json to remove grunt from the devDependencies.
I already had grunt installed globally, so didn't need it in the project too.
Running
npm install -D grunt-exec
a second time worked for me and my updated devDependencies now looks like this:
"devDependencies": {
"chai": "^3.5.0",
"grunt": "^0.4.5",
"grunt-contrib-clean": ">0.4.0",
"grunt-contrib-concat": "^1.0.0",
"grunt-contrib-jshint": "~1.0.0",
"grunt-contrib-uglify": "^1.0.1",
"grunt-exec": "^0.4.6",
"grunt-mocha-test": "^0.12.7",
"mocha": "^2.4.5"
},
with the new lines being grunt, and grunt-exec.
So far my project works as it did before adding grunt-exec. It looks like I just found a simple way to downgrade to an earlier version of grunt.
Here's the version info from the global install:
>grunt -V
grunt-cli v1.2.0
grunt v0.4.5
Hope this helps.

how to use nodejs packages in meteor

how to use nodejs package in meteor app.
i tried to install module in app directory it is showing error
npm install skimlinksjs
npm WARN package.json node#0.0.0 No description
npm WARN package.json node#0.0.0 No repository field.
npm http GET https://registry.npmjs.org/skimlinksjs
npm http 304 https://registry.npmjs.org/skimlinksjs
npm WARN engine skimlinksjs#0.0.1: wanted: {"node":"~0.6.15"} (current: {"node":"v0.10.24","npm":"1.3.21"})
skimlinksjs#0.0.1 ../../node_modules/skimlinksjs
What is this error and how to use it in the app?
Don't do that, and remove the node_modules directory. Most node modules will not work like that due to Meteor's file wrapping and ordering. They just won't load properly.
To use a node module:
Grab npm package via mrt add npm command.
Add packages.json file with the list of necessary packages, for example:
{
"candle": "0.4.0",
"oauth": "0.9.11"
}
Afterwards, you can require the package with Meteor.require('packagename');.

Resources