【问题标题】:Node js app not deploying to heroku throws error `octal literals are not allowed in strict mode`节点 js 应用程序未部署到 heroku 会引发错误“严格模式下不允许使用八进制文字”
【发布时间】:2019-10-27 02:10:31
【问题描述】:

当我推送到 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
    }]
  ]
}

可能是什么问题?

【问题讨论】:

  • 你是说它在本地有效,但在 heroku 上无效?
  • 0-led 八进制文字已被弃用。请改用0o755
  • @Bergi 是的,它在本地工作,但是当我部署到 Heroku 时出现上述错误并失败
  • 这是一个在 Heroku dynos 上没有正确解释相对路径的问题,我遇到了同样的问题(babel --ignore 标志不起作用)。你解决了这个问题吗?

标签: javascript node.js heroku


【解决方案1】:

0755 被解释为八进制数,在 javascript 中都以 0 开始(编辑:用于开始),因此出现错误。所以 0755 在技术上是十进制数 493 并以这种方式解释。

这里真正的问题是没有数字前导零这样的东西。

快速解决方法是使用数字755,不带前导0,或者使用字符串"0755"。不知道这将如何影响其余代码。如果需要八进制,也许 babel 有八进制的解析选项,你可以添加到配置中?

编辑

显然,在严格模式下也禁止使用这种语法的八进制文字。

Number with leading zero in JavaScript

因此,如果您需要八进制数,请尝试0o755

【讨论】:

  • 当我部署到 Heroku 时,节点模块中的某些东西会引发此错误,我无法更改它。其次,它在本地运行良好
猜你喜欢
  • 2018-11-11
  • 2016-08-21
  • 2021-03-31
  • 2021-08-18
  • 1970-01-01
  • 2021-08-29
  • 2014-06-29
  • 1970-01-01
  • 2014-10-21
相关资源
最近更新 更多