当我推送到heroku master时,我的部署失败,并出现以下错误:
remote: { SyntaxError: /tmp/build_396711075a2ae75358d2c942f9c73c1c/.heroku/node/lib/node_modules/npm/node_modules/cmd-shim/index.js: Legacy octal literals are not allowed in strict mode (166:15)
remote:
remote: 164 | function chmodShim (to, cb) {
remote: 165 | var then = times(2, cb, cb)
remote: > 166 | fs.chmod(to, 0755, then)
remote: | ^
remote: 167 | fs.chmod(to + ".cmd", 0755, then)
remote: 168 | }
remote: 169 |
remote: at Parser.raise (/tmp/build_396711075a2ae75358d2c942f9c73c1c/node_modules/@babel/parser/lib/index.js:6344:17)
remote: at Parser.readNumber (/tmp/build_396711075a2ae75358d2c942f9c73c1c/node_modules/@babel/parser/lib/index.js:7194:14)
remote: at Parser.getTokenFromCode (/tmp/build_396711075a2ae75358d2c942f9c73c1c/node_modules/@babel/parser/lib/index.js:6966:14)
remote: at Parser.nextToken (/tmp/build_396711075a2ae75358d2c942f9c73c1c/node_modules/@babel/parser/lib/index.js:6542:12)
remote: at Parser.next (/tmp/build_396711075a2ae75358d2c942f9c73c1c/node_modules/@babel/parser/lib/index.js:6482:10)
remote: at Parser.eat (/tmp/build_396711075a2ae75358d2c942f9c73c1c/node_modules/@babel/parser/lib/index.js:6487:12)
remote: at Parser.expect (/tmp/build_396711075a2ae75358d2c942f9c73c1c/node_modules/@babel/parser/lib/index.js:7645:10)
remote: at Parser.parseCallExpressionArguments (/tmp/build_396711075a2ae75358d2c942f9c73c1c/node_modules/@babel/parser/lib/index.js:8605:14)
remote: at Parser.parseSubscript (/tmp/build_396711075a2ae75358d2c942f9c73c1c/node_modules/@babel/parser/lib/index.js:8515:29)
remote: at Parser.parseSubscripts (/tmp/build_396711075a2ae75358d2c942f9c73c1c/node_modules/@babel/parser/lib/index.js:8434:19)
remote: pos: 4390,
remote: loc: Position { line: 166, column: 15 },
remote: code: 'BABEL_PARSE_ERROR' }
我的babel配置如下所示:
{
"presets": [
[
"@babel/preset-env", {
"targets": {
"node": "current"
}
}
]
],
"plugins": [
"@babel/plugin-proposal-object-rest-spread",
["@babel/plugin-transform-classes", {
"loose": true
}]
]
}
可能是什么问题?
答案 0 :(得分:0)
0755
被解释为一个八进制数字,它们在javascript中都以0开头((编辑:用于开始)),因此会出现错误。因此0755从技术上来说是十进制数字493,并以此方式进行解释。
这里的真正问题是,没有数字前导零这样的东西。
快速解决方案是使用数字755
(不带前导0)或使用字符串"0755"
。不过,不知道这将如何影响其余的代码。如果需要八进制,也许babel有解析选项可以添加到配置中?
编辑:
显然,也禁止在严格模式下以这种语法使用八进制文字。
Number with leading zero in JavaScript
因此,如果您需要八进制数字,请尝试0o755
。