1. 程式人生 > >macOS 升級後 nvm 安裝的 node 和 npm 出錯

macOS 升級後 nvm 安裝的 node 和 npm 出錯

macOS 升級後,發現用 nvm 安裝的 node 和 npm 命令全都沒了,開啟命令列工具的時候會有如下錯誤提示:

internal/modules/cjs/loader.js:583
    throw err;
    ^

Error: Cannot find module 'ansi-regex'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:581:15)
    at Function.Module._load (internal/modules/cjs/loader.js:507:25)
    at Module.require (internal/modules/cjs/loader.js:637:17)
    at require (internal/modules/cjs/helpers.js:20:18)
    at Object.<anonymous> (/Users/rrdawlx/.nvm/versions/node/v10.10.0/lib/node_modules/npm/node_modules/strip-ansi/index.js:2:17)
    at Module._compile (internal/modules/cjs/loader.js:689:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)
nvm is not compatible with the npm config "prefix" option: currently set to ""
Run `nvm use --delete-prefix v10.10.0 --silent` to unset it.

解決方法是先刪除已安裝的 node 版本,比如nvm uninstall v10.10.0;然後重新安裝 node,比如nvm install node