node.js - npm start 给出奇怪的错误 8 和 Unexpected token ILLEGAL

标签 node.js npm-start

在执行 $ npm start 时,我收到奇怪的错误 8,输出如下

SyntaxError: Unexpected token ILLEGAL
at Module._compile (module.js:439:25)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:902:3
npm ERR! weird error 8
npm WARN This failure might be due to the use of legacy binary "node"
npm WARN For further explanations, please read
/usr/share/doc/nodejs/README.Debian

npm ERR! not ok code 0

npm-v 1.3.10

Node -v v0.10.25

我已经安装了nodejs-legacy

$ which node
/usr/bin/node

$ which nodejs
/usr/bin/nodejs

有人可以帮忙吗?

我正在尝试在 ubuntu 14.04 上运行 React-jsonschema-form 或 word-finder ( https://github.com/amirrajan/word-finder )

最佳答案

您正在使用 Node 0.10 - 当前 LTS 版本为 4.5.0,当前版本为 6.6.0。考虑升级 Node,因为您使用的是非常过时的版本。 Node 0.10于2013年3月发布,维护期一周后(2016年10月1日)结束,之后将不再获得任何更新,参见:https://github.com/nodejs/LTS#lts_schedule

根据package.jsongithub.com/mozilla-services/react-jsonschema-form所需的 Node 版本至少为 6.x 和 npm 2.14.7。您正在尝试在 Node v0.10.25 和 npm 1.3.10 上运行它。你不应该指望它能起作用。

要安装现代版本的 Node,您可以从 https://nodejs.org/ 下载二进制版本。或者您可以从源代码构建它,例如使用类似于此的过程:

如果您希望将 node 安装在 /usr/local 中并作为 /usr/local/bin/node 使用,您可以执行以下操作:

# change dir to your home:
cd ~
# download the source:
curl -O https://nodejs.org/dist/v6.6.0/node-v6.6.0.tar.gz
# extract the archive:
tar xzvf node-v6.6.0.tar.gz
# go into the extracted dir:
cd node-v6.6.0
# configure for installation:
./configure --prefix=/usr/local
# build and test:
make && make test
# install:
sudo make install
# make sure you have /usr/local/bin in your $PATH before /usr/bin:
# add this to your .profile or .bashrc:
PATH="/usr/local/bin:$PATH"

或者,如果您希望能够同时安装几个版本,并使用指向要使用的默认版本的符号链接(symbolic link):

# change dir to your home:
cd ~
# download the source:
curl -O https://nodejs.org/dist/v6.6.0/node-v6.6.0.tar.gz
# extract the archive:
tar xzvf node-v6.6.0.tar.gz
# go into the extracted dir:
cd node-v6.6.0
# configure for installation:
./configure --prefix=/opt/node-v6.6.0
# build and test:
make && make test
# install:
sudo make install
# make a symlink to that version:
sudo ln -svf /opt/node-v6.6.0 /opt/node
# make sure you have /opt/node/bin in your $PATH before /usr/bin
# add this to your .profile or .bashrc:
PATH="/opt/node/bin:$PATH"

参见this answer了解更多信息。

关于node.js - npm start 给出奇怪的错误 8 和 Unexpected token ILLEGAL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39639770/

相关文章:

javascript - 如何重置使用 edit-json-file 编辑的文件

javascript - 套接字远程端口代表什么?

javascript - 如何使用 mongoskin 指定单独的用户名和密码参数?

node.js - NextJS Docker 容器与 .env.production

git - 为什么在将应用程序部署到 Heroku 时出现此错误?

react-native - 如何使用 Expo 清理(重置缓存)React Native。不确定是否是缓存问题

javascript - 从 URL 获取图像作为缓冲区

reactjs - 当我运行 "npm start"来运行 React 应用程序时,它没有给出任何错误,而是永远挂起

javascript - 在 'npm start' 命令中自定义构建目录

angular - ng 服务在 Windows 中不工作