一次node升级产生的bug记录

bug 记录

首先,是想本地安装lighthouse进行网站优化检测,安装好后运行命令报错

lighthouse
/usr/local/lib/node_modules/lighthouse/lighthouse-core/gather/driver.js:68
  _traceCategories = Driver.traceCategories;
                   ^
SyntaxError: Unexpected token =
    at new Script (vm.js:74:7)
    at createScript (vm.js:246:10)
    at Object.runInThisContext (vm.js:298:10)
    at Module._compile (internal/modules/cjs/loader.js:657:28)
    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)
    at Module.require (internal/modules/cjs/loader.js:637:17)
    at require (internal/modules/cjs/helpers.js:20:18)

查了下相关issues,lighthouse版本要求node最低v12 issues (opens new window)

于是继续升级node,由于我是用homebrew安装的node,所以直接

brew upgrade node

升完级node版本14,lighthouse成功运行。

然后,npm 报错了

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

Error: Cannot find module '../lib/utils/unsupported.js'
Require stack:
- /usr/local/lib/node_modules/npm/bin/npm-cli.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:1080:15)
    at Function.Module._load (internal/modules/cjs/loader.js:923:27)
    at Module.require (internal/modules/cjs/loader.js:1140:19)
    at require (internal/modules/cjs/helpers.js:75:18)
    at /usr/local/lib/node_modules/npm/bin/npm-cli.js:19:21
    at Object.<anonymous> (/usr/local/lib/node_modules/npm/bin/npm-cli.js:155:3)
    at Module._compile (internal/modules/cjs/loader.js:1251:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1272:10)
    at Module.load (internal/modules/cjs/loader.js:1100:32)
    at Function.Module._load (internal/modules/cjs/loader.js:962:14) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [ '/usr/local/lib/node_modules/npm/bin/npm-cli.js' ]
}

查了半天,最终彻底卸载重装得已解决。

brew uninstall node
#Error: Refusing to uninstall /usr/local/Cellar/node/14.8.0
#because it is required by yarn, which is currently installed.
#You can override this and force removal with:

brew uninstall --ignore-dependencies node

sudo rm -rf /usr/local/lib/node_modules/npm
# Uninstalling /usr/local/Cellar/node/14.8.0... (4,670 files, 61.8MB)

brew install node

相关issues (opens new window)

最近更新
01
echarts扇形模拟镜头焦距与可视化角度示意图
03-10
02
vite插件钩子
03-02
03
vite的依赖预构建
02-13
更多文章>