Not able to run nodemon (SyntaxError: Unexpected token) on ubuntu

Not able to run nodemon (SyntaxError: Unexpected token) on ubuntu

command 我是 运行ning : nodemon server.js, 我得到的错误:

nodemon server.js
/usr/local/lib/node_modules/nodemon/node_modules/update-notifier/index.js:58
            } catch {
                    ^

SyntaxError: Unexpected token {
    at createScript (vm.js:80:10)
    at Object.runInThisContext (vm.js:139:10)
    at Module._compile (module.js:616:28)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/usr/local/lib/node_modules/nodemon/bin/nodemon.js:15:3)

我尝试了多种在 Ubuntu 上安装 nodemon 的方法,但每次 运行.

时仍然出现完全相同的错误

一个原因可能是您的 node.js 安装已过时。 您应该升级到 node.js 的最新版本 您可以通过以下方式检查版本:

node -v

如果版本是最新的,那么你应该尝试使用这个命令全局安装 nodemon

npm install -g nodemon # or using yarn: yarn global add nodemon

如果您卡在旧版本 node.js 中,请执行以下操作:

sudo apt-get remove nodejs
sudo apt-get remove npm

然后转到 /etc/apt/sources.list.d 并删除任何节点列表(如果有)。然后做一个

sudo apt-get update

检查您的主文件夹中的任何 .npm.node 文件夹并将其删除。

如果你输入

which node

可以看到节点的位置。也试试 which nodejswhich npm

然后像这样进行全新安装

cd ~
curl -sL https://deb.nodesource.com/setup_16.x -o nodesource_setup.sh
nano nodesource_setup.sh
sudo bash nodesource_setup.sh
sudo apt install nodejs