如何修复NPM无法全局安装TypeScript错误

时间:2018-12-19 23:52:48

标签: node.js typescript npm npm-install node-modules

尝试使用npm全局安装打字稿时

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 ]

任何帮助都将是无价之宝!

2 个答案:

答案 0 :(得分:1)

我通过从网上重新安装Node JS来解决此问题。

安装此打字稿后,没有错误。

答案 1 :(得分:0)

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

正常尝试,如果不能尝试:npm install --no-bin-links typescript