npm init 不起作用,ENOENT:没有这样的文件或目录
npm init doesn't work, ENOENT: no such file or directory
我在我的 window10 上安装了 node 14(LTS),npm 是自动安装的,但是 npm init
不工作。
我检查它们的版本是否有效
C:\Users\RURU\Documents\practice\css> node -v
// 14.4
C:\Users\RURU\Documents\practice\css> npm -v
// 6
但是,当我想初始化 package.json.
时,npm init
不起作用
C:\Users\RURU\Documents\practice\css> npm init # neither npm init -y
错误:
npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path C:\Users\RURU\Documents\practice\css\package.json
npm ERR! errno -4058
npm ERR! enoent ENOENT: no such file or directory, open 'C:\Users\RURU\Documents\practice\css\package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\RURU\AppData\Local\npm-cache\_logs21-07-04T14_37_28_289Z-debug.log
错误日志:
0 info it worked if it ends with ok
1 verbose cli [
1 verbose cli 'C:\Program Files\nodejs\node.exe',
1 verbose cli 'C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js',
1 verbose cli 'init'
1 verbose cli ]
2 info using npm@6.14.13
3 info using node@v14.17.2
4 silly package data {
4 silly package data name: 'c',
4 silly package data version: '1.0.0',
4 silly package data description: '',
4 silly package data main: 'index.js',
4 silly package data scripts: { test: 'echo "Error: no test specified" && exit 1' },
4 silly package data author: 'ru',
4 silly package data license: 'ISC'
4 silly package data }
5 info init written successfully
6 verbose stack Error: ENOENT: no such file or directory, open 'C:\Users\RURU\Documents\practice\css\package.json'
7 verbose cwd C:\Users\RURU\Documents\practice\css
8 verbose Windows_NT 10.0.19042
9 verbose argv "C:\Program Files\nodejs\node.exe" "C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js" "init"
10 verbose node v14.17.2
11 verbose npm v6.14.13
12 error code ENOENT
13 error syscall open
14 error path C:\Users\RURU\Documents\practice\css\package.json
15 error errno -4058
16 error enoent ENOENT: no such file or directory, open 'C:\Users\RURU\Documents\practice\css\package.json'
17 error enoent This is related to npm not being able to find a file.
18 verbose exit [ -4058, true ]
我不知道如何解决它,任何人都可以帮忙......
我的路
C:\Program Files\nodejs\;C:\Users\RURU\AppData\Roaming\npm
您可以使用 2 种方法来解决问题:
- 以管理员模式启动cmd,然后重试。
- 运行 命令使用 --unsafe-perms 即
npm init --unsafe-perms
我认为在大多数情况下不需要 2 个步骤。
我在我的 window10 上安装了 node 14(LTS),npm 是自动安装的,但是 npm init
不工作。
我检查它们的版本是否有效
C:\Users\RURU\Documents\practice\css> node -v
// 14.4
C:\Users\RURU\Documents\practice\css> npm -v
// 6
但是,当我想初始化 package.json.
时,npm init
不起作用
C:\Users\RURU\Documents\practice\css> npm init # neither npm init -y
错误:
npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path C:\Users\RURU\Documents\practice\css\package.json
npm ERR! errno -4058
npm ERR! enoent ENOENT: no such file or directory, open 'C:\Users\RURU\Documents\practice\css\package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\RURU\AppData\Local\npm-cache\_logs21-07-04T14_37_28_289Z-debug.log
错误日志:
0 info it worked if it ends with ok
1 verbose cli [
1 verbose cli 'C:\Program Files\nodejs\node.exe',
1 verbose cli 'C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js',
1 verbose cli 'init'
1 verbose cli ]
2 info using npm@6.14.13
3 info using node@v14.17.2
4 silly package data {
4 silly package data name: 'c',
4 silly package data version: '1.0.0',
4 silly package data description: '',
4 silly package data main: 'index.js',
4 silly package data scripts: { test: 'echo "Error: no test specified" && exit 1' },
4 silly package data author: 'ru',
4 silly package data license: 'ISC'
4 silly package data }
5 info init written successfully
6 verbose stack Error: ENOENT: no such file or directory, open 'C:\Users\RURU\Documents\practice\css\package.json'
7 verbose cwd C:\Users\RURU\Documents\practice\css
8 verbose Windows_NT 10.0.19042
9 verbose argv "C:\Program Files\nodejs\node.exe" "C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js" "init"
10 verbose node v14.17.2
11 verbose npm v6.14.13
12 error code ENOENT
13 error syscall open
14 error path C:\Users\RURU\Documents\practice\css\package.json
15 error errno -4058
16 error enoent ENOENT: no such file or directory, open 'C:\Users\RURU\Documents\practice\css\package.json'
17 error enoent This is related to npm not being able to find a file.
18 verbose exit [ -4058, true ]
我不知道如何解决它,任何人都可以帮忙......
我的路
C:\Program Files\nodejs\;C:\Users\RURU\AppData\Roaming\npm
您可以使用 2 种方法来解决问题:
- 以管理员模式启动cmd,然后重试。
- 运行 命令使用 --unsafe-perms 即
npm init --unsafe-perms
我认为在大多数情况下不需要 2 个步骤。