Javascript 节点js应用程序未部署到heroku时抛出错误`严格模式下不允许使用八进制文字`
当我推送到heroku master时,我的部署失败,出现以下错误:Javascript 节点js应用程序未部署到heroku时抛出错误`严格模式下不允许使用八进制文字`,javascript,node.js,heroku,Javascript,Node.js,Heroku,当我推送到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: 1
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
}]
]
}
可能是什么问题?
0755
被解释为一个八进制数,在javascript中,所有八进制数都以0开始(编辑:用于开始),因此出现错误。所以0755从技术上讲是十进制数493,并且可以这样解释
这里真正的问题是不存在数字的前导零
快速修复方法是使用数字755
,不带前导0,或者使用字符串“0755”
。但是,不知道这将如何影响代码的其余部分。如果需要八进制,也许babel有八进制的解析选项,您可以添加到配置中
编辑:
显然,在严格模式下,这种语法也禁止使用八进制文字
因此,如果您需要八进制数字,请尝试
0o755
您是说它在本地工作,但在heroku上不工作?0
-led八进制文字不推荐使用。改为使用0o755
。@Bergi是的,它在本地工作,但在部署到Heroku时失败,出现上述错误。这是一个在Heroku dynos上无法正确解释相对路径的问题,我遇到了相同的问题(babel--ignore
标志不起作用)。你解决了这个问题吗?当我部署到Heroku时,节点模块中的某些东西抛出了这个错误,我无法更改它。其次,它在本地运行良好