"npm install" not installing any library. How to resolve this issue? - javascript

I am using Node version 14.15.5 and npm version 6.14.11. Also, I am working on VS Code.
I have tried to install two packages by these commands:
npm install express
npm install lodash
In the end, I am not getting any of them successfully.
I received this message:
36 packages are looking for funding
run `npm fund` for details.
How to resolve this issue?
enter image description here

The reason is described here:
Before installing a package into the local folder, NPM tries to find the root of your package. To do this it walks from your current directory (C:\Users\JD Mughal\Desktop\Web\Node\test-calculator) up the hierarchy until it finds a package.json file.
Only if no package.json file is found will NPM install the new package in the current directory (respectively in a node_modules\package_name subdirectory).
In your case however NPM finds a package.json file C:\Users\JD Mughal\package.json and installs the new package there.
To resolve the use you must execute npm init in your local directory.

Related

npm ERR! could not detect node name from path or package

today i was trying to install my package in visual studio. But there is an error:
enter image description here
npm i
npm ERR! could not detect node name from path or package
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\holan\AppData\Local\npm-cache_logs\2021-09-01T00_08_12_922Z-debug.log
I reinstall node.js and python
here is my path
enter image description here
sorry for my bad english but i need help
As OP didn't provide details of the issue and seems to be new to nodejs, hereby explaining how npm i work in general matter.
There are main usage of npm i:
To install a package that haven't install in this project(or global) before, you can put that package name after the npm i , such as npm i express. Once the installation is done, it will insert the package name into package.json and the package source code in node_modules. You can think package.json is like a index and node_modules is the actual packages source code.
To install a package that listed in package.json. If you are copying/clone the project from other source , usually it has package.json but not the node_modules. In that case, you can use npm i to install all the packages that listed in package.json and it will then create the node_modules.
Using npm i without package.json will not install anything as there isn't a package name in the npm i [package name] and package.json .

module npm file doesn't appear to me

I am trying to follow with pluralsight tutorial and he wrote npm install on the terminal, then a file called npm module is installed on the folder he specified. when I try to install npm this appears to me in the terminal, and the directory which Im trying to install npm on it contains only one document called package-lock.json enter image description here
npm install uses the package.json to install the necessary packages
I can see when you ls, there's no package.json in the directory, just the package-lock which is created where ever you run npm install
Make sure you run the npm install from the same directory the package.json in contained in
the problem is solved, I think that I download the web-dev-starter folder twice by mistake.

Why can't find package required on the "npm" registry

I have problems running my web app using this tutorial video React Native Web Full App Tutorial - Build a Workout App for iOS, Android, and Web
in react-native. I've been searching a lot for an answer but there is no accurate one yet that solves my issue.
I downloaded the app from here: git repo.
Try to use:
$ yarn
$ yarn install
$ npm install
$ npm config set #icons:registry https://registry.npmjs.org/
$ rm -rf node_modules
$ npm i https://github.com/Qix-/node-error-ex
$ curl 'https://registry.yarnpkg.com/#types/node/-/node-9.4.2.tgz'
but nothing seems to work, I keep getting this error.
error Couldn't find package "#wow/common#1.0.0" required by "#wow/app#0.0.1" on the "npm" registry.
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
Error: Couldn't find package "#wow/common#1.0.0" required by "react-native-web-workout-series#0.1.0" on the "npm" registry.
at MessageError.ExtendableBuiltin (/usr/local/Cellar/yarn/1.22.4/libexec/lib/cli.js:721:66)
at new MessageError (/usr/local/Cellar/yarn/1.22.4/libexec/lib/cli.js:750:123)
at PackageRequest.<anonymous> (/usr/local/Cellar/yarn/1.22.4/libexec/lib/cli.js:36539:17)
at Generator.throw (<anonymous>)
at step (/usr/local/Cellar/yarn/1.22.4/libexec/lib/cli.js:310:30)
at /usr/local/Cellar/yarn/1.22.4/libexec/lib/cli.js:323:13
at processTicksAndRejections (internal/process/task_queues.js:97:5)
Or any steps I need to follow to run this app. Since I want to download the app and edit the body content.
I tried to download and test it myself and it worked normally.
Clone it again and follow these steps:
#After cloning enter the folder
cd react-native-web-series
#install all dependencies
yarn install
#Navigate to the web folder
cd packages/web
#start the app
yarn start
Ps. : If a project is using yarn is not a good ideia to run npm commands, do not mix those two
In my case, the reason was the .npmrc file.
You can rename this file
mv ~/.npmrc ~/.npmrc2
npx create-react-app my-app
and rename it back after the installation.
mv ~/.npmrc2 ~/.npmrc
I ran into the same problem here.
And just as #Dmitry Grinko mentioned, it is related to .npmrc file.
I used private npm registry before so that some of package is missing.
Using following registry will pass the problem.
registry=https://registry.npmjs.org/
use npm login in terminal to login into your npm registry.
More information available here:
https://github.com/yarnpkg/yarn/issues/6029
npm install -g npm#latest
npm config set registry https://registry.npmjs.org/
If you're using nvm
nvm install 14.18.0
nvm use 14.18.0
nvm alias default 14.18.0
after look on the git repo - i think that maybe you should try to run npm i (or other commands - im not from react native area) in any package(app,common,web) to itself - like I saw any one of them has package.json of his own

npm wont start a react app, requires a dependency: "webpack-dev-server": "3.1.14"

I am trying to create a new react-app and start it, I have created react apps before with no errors but this time when i npm start i get this error
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-dev-server": "3.1.14"
Don't try to install it manually: your package manager does it
automatically.
However, a different version of webpack-dev-server was detected higher up
in the tree:
C:\Users\ashraf\node_modules\webpack-dev-server (version: 3.1.9)
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 "webpack-dev-server" 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.
If this has not helped, there are a few other things you can try:
5. 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.
6. Check if C:\Users\ashraf\node_modules\webpack-dev-server is outside
your project directory.
For example, you might have accidentally installed something in your home
folder.
7. Try running npm ls webpack-dev-server in your project folder.
This will tell you which other package (apart from the expected react-
scripts) installed webpack-dev-server.
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! learnreact#0.1.0 start: `react-scripts start`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the learnreact#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\ashraf\AppData\Roaming\npm-cache\_logs\2019-02-
04T20_36_39_924Z-debug.log
PS C:\Users\ashraf\Desktop\Files\LearnReact\learnreact>
i have tried all the steps in detail in the error log but its still not working, any thoughts on what is causing this error? Thanks in advance
It seems like you want to depend on webpack-dev-server inside your local project.
Perhaps you need to run npm install in your project, instead of your ~ home directory?
from your output, notice these lines.
However, a different version of webpack-dev-server was detected higher up
in the tree:
C:\Users\ashraf\node_modules\webpack-dev-server (version: 3.1.9)
...
6. Check if C:\Users\ashraf\node_modules\webpack-dev-server is outside
your project directory.
For example, you might have accidentally installed something in your home
folder.
so I would
cd ./my-project
npm i
Did you install webpack-dev-server on its own? It seems it has been installed either by you or by another project install. Webpack is for your local development environment so the other install is close enough to your project to interfere with the copy that react is trying to install in your project folder. Steps 1-4 in your error message should resolve your issue. If you have done that and its still not working, did you get different error messages with your next attempt to install your react package?
I have faced the same issue and this method worked for me.
Do follow the steps:
Start terminal from the desktop and write this command:
npm uninstall webpack-dev-server
This will uninstall webpack-dev-server package globally from you node modules.
Go back to you the terminal of your project and install webpack-dev-server package:
npm install webpack-dev-server#version
Note: The version part (above) should equal the versions asked for in the error message.
npm install webpack-dev-server
Now start npm:
npm start
This error mostly occurs when you have created your project using the
npx create-react-app command instead of the npm create-react-app command.

Where does npm install packages?

Can someone tell me where can I find the Node.js modules, which I installed using npm?
Global libraries
You can run npm list -g to see which global libraries are installed and where they're located. Use npm list -g | head -1 for truncated output showing just the path. If you want to display only main packages not its sub-packages which installs along with it - you can use - npm list --depth=0 which will show all packages and for getting only globally installed packages, just add -g i.e. npm list -g --depth=0.
On Unix systems they are normally placed in /usr/local/lib/node or /usr/local/lib/node_modules when installed globally. If you set the NODE_PATH environment variable to this path, the modules can be found by node.
Windows XP - %USERPROFILE%\AppData\npm\node_modules
Windows 7, 8 and 10 - %USERPROFILE%\AppData\Roaming\npm\node_modules
Non-global libraries
Non-global libraries are installed the node_modules sub folder in the folder you are currently in.
You can run npm list to see the installed non-global libraries for your current location.
When installing use -g option to install globally
npm install -g pm2 - pm2 will be installed globally. It will then typically be found in /usr/local/lib/node_modules (Use npm root -g to check where.)
npm install pm2 - pm2 will be installed locally. It will then typically be found in the local directory in /node_modules
The command npm root will tell you the effective installation directory of your npm packages.
If your current working directory is a node package or a sub-directory of a node package, npm root will tell you the local installation directory. npm root -g will show the global installation root regardless of current working directory.
Example:
$ npm root -g
/usr/local/lib/node_modules
See the documentation.
For globally-installed modules:
The other answers give you platform-specific responses, but a generic one is this:
When you install global module with npm install -g something, npm looks up a config variable prefix to know where to install the module.
You can get that value by running npm config get prefix
To display all the global modules available in that folder use npm ls -g --depth 0 (depth 0 to not display their dependencies).
If you want to change the global modules path, use npm config edit and put prefix = /my/npm/global/modules/prefix in the file or use npm config set prefix /my/npm/global/modules/prefix.
When you use some tools like nodist, they change the platform-default installation path of global npm modules.
On windows I used npm list -g to find it out. By default my (global) packages were being installed to C:\Users\[Username]\AppData\Roaming\npm.
If you are looking for the executable that npm installed, maybe because you would like to put it in your PATH, you can simply do
npm bin
or
npm bin -g
If a module was installed with the global (-g) flag, you can get the parent location by running:
npm get prefix
or
npm ls -g --depth=0
which will print the location along with the list of installed modules.
Not direct answer but may help ....
The npm also has a cache folder, which can be found by running npm config get cache (%AppData%/npm-cache on Windows).
The npm modules are first downloaded here and then copied to npm global folder (%AppData%/Roaming/npm on Windows) or project specific folder (your-project/node_modules).
So if you want to track npm packages, and some how, the list of all downloaded npm packages (if the npm cache is not cleaned) have a look at this folder. The folder structure is as {cache}/{name}/{version}
This may help also https://docs.npmjs.com/cli/cache
In earlier versions of NPM modules were always placed in /usr/local/lib/node or wherever you specified the npm root within the .npmrc file. However, in NPM 1.0+ modules are installed in two places. You can have modules installed local to your application in /.node_modules or you can have them installed globally which will use the above.
More information can be found at https://github.com/isaacs/npm/blob/master/doc/install.md
To get a compact list without dependencies simply use
npm list -g --depth 0
The easiest way would be to do
npm list -g
to list the package and view their installed location.
I had installed npm via chololatey, so the location is
C:\MyProgramData\chocolatey\lib\nodejs.commandline.0.10.31\tools\node_modules
C:\MyProgramData\ is chocolatey repo location.
As the other answers say, the best way is to do
npm list -g
However, if you have a large number of npm packages installed, the output of this command could be very long and a big pain to scroll up (sometimes it's not even possible to scroll that far back).
In this case, pipe the output to the more program, like this
npm list -g | more
I was beginning to go mad while searching for the real configuration, so here is the list of all configuration files on linux:
/etc/npmrc
/home/youruser/.npmrc
/root/.npmrc
./.npmrc in the current directory next to package.json file (thanks to #CyrillePontvieux)
on windows:
c/Program\ Files/nodejs/node_modules/npm/npmrc
Then in this file the prefix is configured:
prefix=/usr
The prefix is defaulted to /usr in linux, to ${APPDATA}\npm in windows
The node modules are under $prefix tree, and the path should contain $prefix/bin
There may be a problem :
When you install globally, you use "sudo su" then the /root/.npmrc may be used!
When you use locally without sudo: for your user its the /home/youruser/.npmrc.
When your path doesn't represent your prefix
When you use npm set -g prefix /usr it sets the /etc/npmrc global, but doesn't override the local
Here is all the informations that were missing to find what is configured where. Hope I have been exhaustive.
You can find globally installed modules by the command
npm list -g
It will provide you the location where node.js modules have been installed.
C:\Users\[Username]\AppData\Roaming\npm
If you install node.js modules locally in a folder, you can type the following command to see the location.
npm list
Echo the config: npm config ls or npm config list
Show all the config settings: npm config ls -l or npm config ls --json
Print the effective node_modules folder: npm root or npm root -g
Print the local prefix: npm prefix or npm prefix -g
(This is the closest parent directory to contain a package.json file or node_modules directory)
npm-config | npm Documentation
npm-root | npm Documentation
npm-prefix | npm Documentation
Expanding upon other answers.
npm list -g
will show you the location of globally installed packages.
If you want to output that list to a file that you can then easily search in your text editor:
npm list -g > ~/Desktop/npmfiles.txt
From the docs:
In npm 1.0, there are two ways to install things:
globally —- This drops modules in {prefix}/lib/node_modules, and puts executable files in {prefix}/bin, where {prefix} is usually
something like /usr/local. It also installs man pages in
{prefix}/share/man, if they’re supplied.
locally —- This installs your package in the current working directory. Node modules go in ./node_modules, executables go in
./node_modules/.bin/, and man pages aren’t installed at all.
You can get your {prefix} with npm config get prefix. (Useful when you installed node with nvm).
From the docs:
Packages are dropped into the node_modules folder under the prefix.
When installing locally, this means that you can
require("packagename") to load its main module, or
require("packagename/lib/path/to/sub/module") to load other modules.
Global installs on Unix systems go to {prefix}/lib/node_modules.
Global installs on Windows go to {prefix}/node_modules (that is, no
lib folder.)
Scoped packages are installed the same way, except they are grouped
together in a sub-folder of the relevant node_modules folder with the
name of that scope prefix by the # symbol, e.g. npm install
#myorg/package would place the package in
{prefix}/node_modules/#myorg/package. See scope for more details.
If you wish to require() a package, then install it locally.
You can get your {prefix} with npm config get prefix. (Useful when you installed node with nvm).
Read about locally.
Read about globally.
Windows 10: When I ran npm prefix -g, I noticed that the install location was inside of the git shell's path that I used to install. Even when that location was added to the path, the command from the globally installed package would not be recognized. Fixed by:
running npm config edit
changing the prefix to 'C:\Users\username\AppData\Roaming\npm'
adding that path to the system path variable
reinstalling the package with -g.
In Ubuntu 14.04 they are installed at
/usr/lib/node_modules
For Windows 7, 8 and 10 -
%USERPROFILE%\AppData\Roaming\npm\node_modules
Note:
If you are somewhere in folder type cd .. until you are in C: directory. Then, type cd %USERPROFILE%\AppData\Roaming\npm\node_modules. Then, magically, %USERPROFILE% will change into Users\YourUserProfile\.
I just wanted to clarify on ideas referred by Decko in the first response. npm list -g will list all the bits you have globally installed. If you need to find your project related npm package then cd 'your angular project xyz', then run npm list. It will show list of modules in npm package. It will also give you list of dependencies missing, and you may require to effectively run that project.
Btw, npm will look for node_modules in parent folders (up to very root) if can not find in local.
If you're trying to access your global dir from code, you can backtrack from process.execPath. For example, to find wsproxy, which is in {NODE_GLOBAL_DIR}/bin/wsproxy, you can just:
path.join(path.dirname(process.execPath), 'wsproxy')
There's also how the npm cli works # ec9fcc1/lib/npm.js#L254 with:
path.resolve(process.execPath, '..', '..')
See also ec9fcc1/lib/install.js#L521:
var globalPackage = path.resolve(npm.globalPrefix,
'lib', 'node_modules', moduleName(pkg))
Where globalPrefix has a default set in ec9fcc1/lib/config/defaults.js#L92-L105 of:
if (process.env.PREFIX) {
globalPrefix = process.env.PREFIX
} else if (process.platform === 'win32') {
// c:\node\node.exe --> prefix=c:\node\
globalPrefix = path.dirname(process.execPath)
} else {
// /usr/local/bin/node --> prefix=/usr/local
globalPrefix = path.dirname(path.dirname(process.execPath))
// destdir only is respected on Unix
if (process.env.DESTDIR) {
globalPrefix = path.join(process.env.DESTDIR, globalPrefix)
}
}
If you have Visual Studio installed, you will find it comes with its own copy of node separate from the one that is on the path when you installed node yourself - Mine is in C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VisualStudio\NodeJs.
If you run the npm command from inside this directory you will find out which node modules are installed inside visual studio.

Categories

Resources