简体   繁体   中英

npm install resulting in 'ENOENT: no such file or directory'

I've installed Node.js for Windows and I'm trying to install a package via npm. The command prompt is in the directory of the project (C:\\Users\\username\\Desktop\\NodeTest), which contains a single helloworld.js file. Upon typing 'npm install express', I receive the following error:

ENOENT: no such file or direcotry, open 'C:\\Users\\username\\package.json

I'm attempting this from a clean install and cmd is running as admin.

Any ideas?

I was facing the same issue. I firstly delete my node_modules and delete the cache by following command:

rm -rf node_modules && npm cache clean --force

then I delete the package-lock.json file from my project and then hit npm install in command prompt and it works.

As already pointed out by Subburaj this is because you are missing a package.json .
Just run npm init to initialize that file for you; afterwards it should work.

If you are working on a Windows machine using Vagrant/VM, there's a chance that symlinks are the culprit for your problem. To determine if that is the case, simply copy your package.json and package-lock.json into a test directory that is not mounted/shared between OSs.

mkdir /tmp/symlinktest
cd {{your directory with your package*.json}}
cp package*.json /tmp/symlinktest
cd /tmp/symlinktest
npm install

If this results in a successful install, you'll need to either exclude the node_modules directory from the mount (there's various articles on doing this, however I can't say I've had success) or run npm install outside the mounted volume.

基本上我在尝试使用 npm 安装时处于离线状态,所以请上网并再次尝试npm install

我删除了 package-lock.json 并且它对我有用。

Check the project folder which you opened in microsoft visual code. Generally you are not in the right path so npm is not able to search the package.json ... My project was in Document/hostel/hostel .. I opened Document/hostel ... So npm tried to find the package.json in Documents folder .. When i entered one level inside to Document/hostel/hostel .. it was fixed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM