node.js - 为什么 "npm run <command>"在任何地方都不起作用?

标签 node.js npm

npm run 不适用于任何项目。因此,我无法安装有后安装脚本的软件包

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   'run',
1 verbose cli   'test'
1 verbose cli ]
2 info using npm@6.13.4
3 info using node@v13.5.0
4 verbose run-script [ 'pretest', 'test', 'posttest' ]
5 info lifecycle myapp@0.0.0~pretest: myapp@0.0.0
6 info lifecycle myapp@0.0.0~test: myapp@0.0.0
7 verbose lifecycle myapp@0.0.0~test: unsafe-perm in lifecycle true
8 verbose lifecycle myapp@0.0.0~test: PATH: C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin;C:\Users\Vombat\Desktop\Learn\express_template_app\myapp\node_modules\.bin;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\iCLS\;C:\Program Files\Intel\Intel(R) Management Engine Components\iCLS\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR;C:\Program Files\Git\cmd;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\nodejs\;C:\Users\Vombat\AppData\Local\Microsoft\WindowsApps;C:\Users\Vombat\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\Vombat\AppData\Roaming\npm
9 verbose lifecycle myapp@0.0.0~test: CWD: C:\Users\Vombat\Desktop\Learn\express_template_app\myapp
10 silly lifecycle myapp@0.0.0~test: Args: [ '-c', 'node -v' ]
11 info lifecycle myapp@0.0.0~test: Failed to exec test script
12 silly lifecycle myapp@0.0.0~test: Returned: code: -4058  signal: null
13 info lifecycle myapp@0.0.0~test: Failed to exec test script
14 verbose stack Error: myapp@0.0.0 test: `node -v`
14 verbose stack spawn = ENOENT
14 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:267:19)
14 verbose stack     at onErrorNT (internal/child_process.js:469:16)
14 verbose stack     at processTicksAndRejections (internal/process/task_queues.js:84:21)
15 verbose pkgid myapp@0.0.0
16 verbose cwd C:\Users\Vombat\Desktop\Learn\express_template_app\myapp
17 verbose Windows_NT 10.0.18362
18 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "test"
19 verbose node v13.5.0
20 verbose npm  v6.13.4
21 error code ELIFECYCLE
22 error syscall spawn =
23 error file =
24 error path =
25 error errno -4058
26 error myapp@0.0.0 test: `node -v`
26 error spawn = ENOENT
27 error Failed at the myapp@0.0.0 test script.
27 error This is probably not a problem with npm. There is likely additional logging output above.
28 verbose exit [ -4058, true ]

我将 Node 更新到最新版本,我尝试了npmcacheclear--forcenpmcacheverify,但没有帮助。 操作系统 Windows 10。 Node 版本 13.5.0,npm 版本 6.13.4

最佳答案

确保您已正确设置 NODE_PATH 环境变量。 该路径必须与您的nodeJS目录匹配 + \node_modules

enter image description here

关于node.js - 为什么 "npm run <command>"在任何地方都不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59479497/

相关文章:

node.js - npm install 在 node_modules 中创建过多的依赖项

javascript - grunt 替换时出现目标未定义错误

django - 使用 Node.js 和 Django 作为后端处理请求

javascript - 尝试将 Promise 传递给另一个函数,然后返回它,得到 "Unhandled promise rejection"

Node.js MongoDB 批量操作 UpdateOne 与 arrayFilters

node.js - 用户登录时 Firebase 创建条目

npm run <command> 不起作用

node.js - Npm 安装失败,docker buildx linux/arm64

docker - 通过 docker 容器运行时 npm install 失败

node.js - npm-cache 目录下,_cacache 以外的文件夹是做什么用的?