无法将“节点”识别为内部或外部命令,可操作程序或批处理文件

时间:2019-07-24 23:58:01

标签: javascript node.js npm

我正在Windows 10中从git-bash-cli运行“ npm install node-sass”,并且无法将“节点”识别为内部或外部命令, 可操作的程序或批处理文件。”错误。

多年以来,我一直在使用此设置,当我将节点升级到10.16.0时,问题开始了。

为避免不必要的答复:

我看到的所有问题都只是添加路径变量。

我已经将Node添加到PATH变量中,并尝试了多种不同的编写方式。我最终重新安装了Node.js,它会自动执行,因此就这样了。

节点从命令行运行,而不是从脚本运行,例如package.json文件中的脚本。

我尝试重新安装节点8.11.3,这是问题开始之前我所使用的版本,但出现相同的错误。我又回到了10.16.0版。

错误代码如下:


> node-sass@4.12.0 install C:\projects\true\true\website\truevue\node_modules\node-sass
> node scripts/install.js

'node' is not recognized as an internal or external command,
operable program or batch file.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.0.7 (node_modules\@nuxt\builder\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.0.7: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.7 (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.7: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! node-sass@4.12.0 install: `node scripts/install.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the node-sass@4.12.0 install 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\Peter\AppData\Roaming\npm-cache\_logs\2019-07-24T23_41_06_896Z-debug.log

这是我在正在处理的Vue项目上运行npm run dev时的日志

1 verbose cli [ 'C:\\Program Files\\nodejs\\node.exe',
1 verbose cli   'C:\\Users\\Peter\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli   'run',
1 verbose cli   'dev' ]
2 info using npm@6.10.2-next.1
3 info using node@v10.16.0
4 verbose run-script [ 'predev', 'dev', 'postdev' ]
5 info lifecycle thisistrue.co@1.0.0~predev: thisistrue.co@1.0.0
6 info lifecycle thisistrue.co@1.0.0~dev: thisistrue.co@1.0.0
7 verbose lifecycle thisistrue.co@1.0.0~dev: unsafe-perm in lifecycle true
8 verbose lifecycle thisistrue.co@1.0.0~dev: PATH: C:\Users\Peter\AppData\Roaming\npm\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin;C:\projects\true\true\website\truevue\node_modules\.bin
9 verbose lifecycle thisistrue.co@1.0.0~dev: CWD: C:\projects\true\true\website\truevue
10 silly lifecycle thisistrue.co@1.0.0~dev: Args: [ '/d /s /c',
10 silly lifecycle   'cross-env NODE_ENV=development nodemon server/index.js --watch server' ]
11 silly lifecycle thisistrue.co@1.0.0~dev: Returned: code: 1  signal: null
12 info lifecycle thisistrue.co@1.0.0~dev: Failed to exec dev script
13 verbose stack Error: thisistrue.co@1.0.0 dev: `cross-env NODE_ENV=development nodemon server/index.js --watch server`
13 verbose stack Exit status 1
13 verbose stack     at EventEmitter.<anonymous> (C:\Users\Peter\AppData\Roaming\npm\node_modules\npm\node_modules\npm-lifecycle\index.js:317:16)
13 verbose stack     at EventEmitter.emit (events.js:198:13)
13 verbose stack     at ChildProcess.<anonymous> (C:\Users\Peter\AppData\Roaming\npm\node_modules\npm\node_modules\npm-lifecycle\lib\spawn.js:55:14)
13 verbose stack     at ChildProcess.emit (events.js:198:13)
13 verbose stack     at maybeClose (internal/child_process.js:982:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:259:5)
14 verbose pkgid thisistrue.co@1.0.0
15 verbose cwd C:\projects\true\true\website\truevue
16 verbose Windows_NT 10.0.17134
17 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\Peter\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js" "run" "dev"
18 verbose node v10.16.0
19 verbose npm  v6.10.2-next.1
20 error code ELIFECYCLE
21 error errno 1
22 error thisistrue.co@1.0.0 dev: `cross-env NODE_ENV=development nodemon server/index.js --watch server`
22 error Exit status 1
23 error Failed at the thisistrue.co@1.0.0 dev script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]

2 个答案:

答案 0 :(得分:1)

最后找到了答案。 我最终所做的只是运行npm update -g,它解决了该问题

感谢所有帮助过的人,希望这可以帮助其他人

答案 1 :(得分:0)

我认为您必须将node.js的路径添加到系统变量

首先:打开控制面板->系统和安全->系统->高级系统设置->环境变量

第二个:在“用户变量”或“系统变量”中找到变量PATH并添加node.js文件夹路径作为值。它是C:\ Program Files \ nodejs;如果不存在,则创建它。

第三:重新启动计算机。