我需要使用基于 ionic Framework v1 和 Cordova 7.1 的应用程序,但运行 Cordova 时 Node 存在以下问题:
$ cordova -v
/node_modules/cordova/node_modules/npm-normalize-package-bin/index.js:3
const {join, basename} = require('path')
^
SyntaxError: Unexpected token {
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:387:25)
at Object.Module._extensions..js (module.js:422:10)
at Module.load (module.js:357:32)
at Function.Module._load (module.js:314:12)
at Module.require (module.js:367:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (node_modules/cordova/node_modules/read-package-json/read-json.js:14:27)
at Module._compile (module.js:413:34)
at Object.Module._extensions..js (module.js:422:10)
我使用以下命令安装了 Cordova:
npm install -g <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="197a766b7d766f78592e37283729" rel="noreferrer noopener nofollow">[email protected]</a>
该项目需要在我的计算机上安装以下版本:
node -v
v5.12.0
npm -v
3.8.6
ionic -v
1.7.15
grunt --version
grunt-cli v0.1.13
grunt v0.4.5
bower -v
1.8.4
plugman -v
2.0.0
有谁知道问题出在哪里吗?我很高兴能得到任何帮助。
最佳答案
问题是nodejs v5.x不支持解构,这在行中使用
const {join, basename} = require('path')
您可以在此处阅读有关 Nodejs 中支持的 js 功能的更多信息,https://node.green/#ES2015-syntax-destructuring--declarations
关于node.js - Node 错误: "SyntaxError: Unexpected token {" at "const {join, basename} = require(' path')",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60435995/