Node.js 如何修复npm无法全局安装typescript错误

Node.js 如何修复npm无法全局安装typescript错误,node.js,typescript,npm,npm-install,node-modules,Node.js,Typescript,Npm,Npm Install,Node Modules,尝试使用npm全局安装typescript时 sudo npm install -g typescript 安装失败,出现以下错误: ENOENT: no such file or directory, chmod '/usr/local/lib/node_modules/typescript/bin/tsc' 日志的完整内容如下所示 0 info it worked if it ends with ok 1 verbose cli [ '/usr/local/bin/node', 1 ve

尝试使用npm全局安装typescript时

sudo npm install -g typescript
安装失败,出现以下错误:

ENOENT: no such file or directory, chmod '/usr/local/lib/node_modules/typescript/bin/tsc'
日志的完整内容如下所示

0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/bin/node',
1 verbose cli   '/usr/local/bin/npm',
1 verbose cli   'install',
1 verbose cli   '-g',
1 verbose cli   'typescript' ]
2 info using npm@6.5.0
3 info using node@v8.11.4
4 verbose npm-session 631fb36c24f0a08c
5 silly install loadCurrentTree
6 silly install readGlobalPackageData
7 http fetch GET 304 https://registry.npmjs.org/typescript 3969ms (from cache)
8 silly pacote tag manifest for typescript@latest fetched in 4025ms
9 timing stage:loadCurrentTree Completed in 4299ms
10 silly install loadIdealTree
11 silly install cloneCurrentTreeToIdealTree
12 timing stage:loadIdealTree:cloneCurrentTree Completed in 0ms
13 silly install loadShrinkwrap
14 timing stage:loadIdealTree:loadShrinkwrap Completed in 2ms
15 silly install loadAllDepsIntoIdealTree
16 silly resolveWithNewModule typescript@3.2.2 checking installable status
17 timing stage:loadIdealTree:loadAllDepsIntoIdealTree Completed in 5ms
18 timing stage:loadIdealTree Completed in 7ms
19 silly currentTree lib
20 silly idealTree lib
20 silly idealTree └── typescript@3.2.2
21 silly install generateActionsToTake
22 timing stage:generateActionsToTake Completed in 4ms
23 silly diffTrees action count 1
24 silly diffTrees add typescript@3.2.2
25 silly decomposeActions action count 8
26 silly decomposeActions fetch typescript@3.2.2
27 silly decomposeActions extract typescript@3.2.2
28 silly decomposeActions preinstall typescript@3.2.2
29 silly decomposeActions build typescript@3.2.2
30 silly decomposeActions install typescript@3.2.2
31 silly decomposeActions postinstall typescript@3.2.2
32 silly decomposeActions finalize typescript@3.2.2
33 silly decomposeActions refresh-package-json typescript@3.2.2
34 silly install executeActions
35 silly doSerial global-install 8
36 verbose correctMkdir /Users/user/.npm/_locks correctMkdir not in flight; initializing
37 verbose lock using /Users/user/.npm/_locks/staging-3a08f0df5026584d.lock for /usr/local/lib/node_modules/.staging
38 silly doParallel extract 1
39 silly extract typescript@3.2.2
40 timing action:extract Completed in 602ms
41 silly doReverseSerial unbuild 8
42 silly doSerial remove 8
43 silly doSerial move 8
44 silly doSerial finalize 8
45 silly finalize /usr/local/lib/node_modules/typescript
46 timing action:finalize Completed in 3ms
47 silly doParallel refresh-package-json 1
48 silly refresh-package-json /usr/local/lib/node_modules/typescript
49 timing action:refresh-package-json Completed in 14ms
50 silly doParallel preinstall 1
51 silly preinstall typescript@3.2.2
52 info lifecycle typescript@3.2.2~preinstall: typescript@3.2.2
53 timing action:preinstall Completed in 1ms
54 silly doSerial build 8
55 silly build typescript@3.2.2
56 info linkStuff typescript@3.2.2
57 silly linkStuff typescript@3.2.2 has /usr/local/lib/node_modules as its parent node_modules
58 silly linkStuff typescript@3.2.2 is part of a global install
59 silly linkStuff typescript@3.2.2 is installed into a global node_modules
60 silly linkStuff typescript@3.2.2 is installed into the top-level global node_modules
61 verbose linkBins [ { tsc: './bin/tsc', tsserver: './bin/tsserver' },
61 verbose linkBins   '/usr/local/bin',
61 verbose linkBins   true ]
62 timing action:build Completed in 3ms
63 verbose unlock done using /Users/user/.npm/_locks/staging-3a08f0df5026584d.lock for /usr/local/lib/node_modules/.staging
64 timing stage:rollbackFailedOptional Completed in 16ms
65 timing stage:runTopLevelLifecycles Completed in 4956ms
66 verbose stack Error: ENOENT: no such file or directory, chmod '/usr/local/lib/node_modules/typescript/bin/tsc'
67 verbose cwd /Users/user/localserver
68 verbose Darwin 18.2.0
69 verbose argv "/usr/local/bin/node" "/usr/local/bin/npm" "install" "-g" "typescript"
70 verbose node v8.11.4
71 verbose npm  v6.5.0
72 error path /usr/local/lib/node_modules/typescript/bin/tsc
73 error code ENOENT
74 error errno -2
75 error syscall chmod
76 error enoent ENOENT: no such file or directory, chmod '/usr/local/lib/node_modules/typescript/bin/tsc'
77 error enoent This is related to npm not being able to find a file.
78 verbose exit [ -2, true ]
任何帮助都是非常感谢的

拉菲。 我建议首先使用: sudo npm安装-g npm sudo npm缓存清除


正常尝试,如果不尝试:npm安装——无bin链接typescript

我通过在线重新安装Node JS修复了这个问题


安装此类型脚本后,没有错误。

您的Linux版本是什么?我正在使用MacOS Mojavee为什么您要
sudo
-ing?我不认为有人应该这样做。在Mac OS上,要全局安装npm模块,必须使用sudo。运行sudo npm install-g npm实际上失败了。我收到了一个类似的错误提示:没有这样的文件或目录,打开“/private/tmp/npm-24943-3e68da42/unpack-a1daac03/node_modules/run queue/package.json”在清理缓存之前尝试运行npm安装我已经运行了npm安装并使用--force模式清除了缓存,但现在在尝试安装npm时收到一个错误。