javascript - 意外的令牌 { 当我需要“express-fileupload”时
问题描述
我试图让文件上传与在 Ubuntu 上运行的 NodeJS 一起工作,但我不断收到错误。添加后
const fileUpload = require('express-fileupload');
该应用程序将不再编译。它会吐出这个错误
2|theproje | /home/asgeir/nodejs/first_test_app/node_modules/express-fileupload/lib/index.js:5
2|theproje | const {buildOptions} = require('./utilities');
2|theproje | ^
2|theproje |
2|theproje | SyntaxError: Unexpected token {
2|theproje | at exports.runInThisContext (vm.js:53:16)
2|theproje | at Module._compile (module.js:374:25)
2|theproje | at Object.Module._extensions..js (module.js:417:10)
2|theproje | at Module.load (module.js:344:32)
2|theproje | at Function.Module._load (module.js:301:12)
2|theproje | at Module.require (module.js:354:17)
2|theproje | at require (internal/module.js:12:17)
2|theproje | at Object.<anonymous> (/home/asgeir/nodejs/first_test_app/server.js:2:20)
2|theproje | at Module._compile (module.js:410:26)
2|theproje | at Object.Module._extensions..js (module.js:417:10)
我猜这一定是版本之间的一些兼容性问题,所以我尝试将 Node 升级到最新版本。Ubuntu 只允许我使用 v4.2.6 版本,所以我未能将其更新到更新版本。
任何有关此错误的帮助,或适用于较旧 NodeJS 版本的文件上传模块的建议将不胜感激!
解决方案
在 ubuntu 中更新到最新的 (LTS) nodejs
curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
sudo apt-get install -y nodejs
或者,最新版本
curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
sudo apt-get install -y nodejs
来源:https ://github.com/nodesource/distributions/blob/master/README.md
推荐阅读
- python - 如何让 Atom 将 Pygame 识别为模块
- python - 我的时间转换器没有添加分钟
- javascript - 如何从我得到的数组中获取特定的数组元素作为调用 axios.get() 调用的函数的响应
- react-native - 世博会推送通知图标和标题
- machine-learning - 是否可以通过机器学习来学习和预测 NaN 值?
- javascript - 如何在 iframe src 中转义脚本标签?
- javascript - 如何在使用 jQuery 刷新(隐藏/显示)DOM 后继续播放 CSS 动画?
- php - 如何在php中更新一行中的多个数据?
- reactjs - 反应输入值
- javascript - CORS 政策已阻止从源“https://gmbexample-f23ef.firebaseapp.com”访问“https://www.googleapis.com/oauth2/v4/token”获取