0

我在 window10 上安装了节点 14(LTS),npm 是自动安装的,但npm init不起作用。

我检查它们的版本是否有效

C:\Users\RURU\Documents\practice\css> node -v
// 14.4
C:\Users\RURU\Documents\practice\css> npm -v
// 6

但是,npm init当我想初始化一个 package.json 时,它不起作用。

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\_logs\2021-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
4

1 回答 1

0

你可以用两件事来解决这个问题:

  1. 以管理员模式启动 cmd,然后重试。
  2. 使用 --unsafe-perms 运行命令,即npm init --unsafe-perms

我认为在大多数情况下不需要 2 步。

于 2021-07-04T07:54:53.493 回答