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

n9vozmp4  于 2023-10-19  发布在  TypeScript
关注(0)|答案(3)|浏览(296)

尝试使用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 [email protected]
3 info using [email protected]
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 [email protected] 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 └── [email protected]
21 silly install generateActionsToTake
22 timing stage:generateActionsToTake Completed in 4ms
23 silly diffTrees action count 1
24 silly diffTrees add [email protected]
25 silly decomposeActions action count 8
26 silly decomposeActions fetch [email protected]
27 silly decomposeActions extract [email protected]
28 silly decomposeActions preinstall [email protected]
29 silly decomposeActions build [email protected]
30 silly decomposeActions install [email protected]
31 silly decomposeActions postinstall [email protected]
32 silly decomposeActions finalize [email protected]
33 silly decomposeActions refresh-package-json [email protected]
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 [email protected]
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 [email protected]
52 info lifecycle [email protected]~preinstall: [email protected]
53 timing action:preinstall Completed in 1ms
54 silly doSerial build 8
55 silly build [email protected]
56 info linkStuff [email protected]
57 silly linkStuff [email protected] has /usr/local/lib/node_modules as its parent node_modules
58 silly linkStuff [email protected] is part of a global install
59 silly linkStuff [email protected] is installed into a global node_modules
60 silly linkStuff [email protected] 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 ]

任何帮助将是非常感谢!

zy1mlcev

zy1mlcev1#

拉菲.我建议使用第一:sudo npm install -g npm sudo npm cache clear
一个正常的尝试,如果不尝试:npm install --no-bin-links typescript

yebdmbv4

yebdmbv42#

首先,我安装一个dev依赖:

npm install typescript --save-dev

然后,我安装全局模块:

sudo npm install -g typescript

这个代码在我的情况下工作

pgpifvop

pgpifvop3#

我通过在线重新安装Node JS修复了这个问题。
在此之后,打字脚本安装没有错误。

相关问题