最近运行一个前端我的项目时,呈现了 Node.js 版本与依赖版本不符的问题,如下:
error @typescript-eslint/eslint-plugin@5.21.0: The engine "node" is incompatible with this module. Expected version "^12.22.0 || ^14.17.0 || >=16.0.0". Got "14.16.0"
error Found incompatible module.
正如下面的谬误提醒,本地装置的 node 版本是 14.16.0,于是打算将版本升级到大于 16.0.0 的版本。
这里介绍一个 node 版本管理工具,能够不便的治理你本地的版本。
装置命令:
npm i n -g
如果呈现了上面的谬误,你须要加上 sudo npm i n -g
➜ quick-demo-vue3-ts git:(main) npm i n -g
npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules
npm ERR! code EACCES
npm ERR! syscall access
npm ERR! path /usr/local/lib/node_modules
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, access '/usr/local/lib/node_modules'
npm ERR! [Error: EACCES: permission denied, access '/usr/local/lib/node_modules'] {
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'access',
npm ERR! path: '/usr/local/lib/node_modules'
npm ERR! }
装置实现后,能够应用上面的命令查看应用办法:
n --help
Usage: n [options] [COMMAND] [args]
Commands:
n Display downloaded Node.js versions and install selection
n latest Install the latest Node.js release (downloading if necessary)
n lts Install the latest LTS Node.js release (downloading if necessary)
n <version> Install Node.js <version> (downloading if necessary)
n install <version> Install Node.js <version> (downloading if necessary)
n run <version> [args ...] Execute downloaded Node.js <version> with [args ...]
n which <version> Output path for downloaded node <version>
n exec <vers> <cmd> [args...] Execute command with modified PATH, so downloaded node <version> and npm first
n rm <version ...> Remove the given downloaded version(s)
n prune Remove all downloaded versions except the installed version
n --latest Output the latest Node.js version available
n --lts Output the latest LTS Node.js version available
n ls Output downloaded versions
n ls-remote [version] Output matching versions available for download
n uninstall Remove the installed Node.js
只有输出 n lts 就能够主动装置稳固版本的 node.js 了。
sudo n lts
installing : node-v16.16.0
mkdir : /usr/local/n/versions/node/16.16.0
fetch : https://nodejs.org/dist/v16.16.0/node-v16.16.0-darwin-arm64.tar.xz
copying : node/16.16.0
installed : v16.16.0 (with npm 8.11.0)
node -v
v16.16.0
除了 n,还有别的 nvm 比拟适宜在 Linux 零碎上应用,大家能够点击链接去查看,这里不在赘述。