尝试在Heroku上构建应用程序时发生Babel Parser错误

时间:2019-04-19 08:05:02

标签: node.js heroku babel

我正在尝试将Node js应用程序部署到Heroku,但是它一直失败。

我已经设置了NPM_CONFIG_PRODUCTION=false。构建脚本在我的本地计算机上工作正常

这是我的package.json文件

"release": "npm run clean && npm run build-app && npm run start",
    "clean": "rm -rf dist && mkdir dist",
    "build": "rm -rf ./dist && mkdir dist && babel . --out-dir dist",
    "build-app": "babel . -s -d dist --presets=@babel/env --ignore node_modules",

构建应该成功,但这是我在Heroku上遇到的错误

> rm -rf ./dist && mkdir dist && babel . --out-dir dist

[BABEL] Note: The code generator has deoptimised the styling of /tmp/build_3a8af19f4cfbd2b3f05ba2bc3775012d/.heroku/node/lib/node_modules/npm/node_modules/ajv/dist/regenerator.min.js as it exceeds the max of 500KB.
{ SyntaxError: /tmp/build_3a8af19f4cfbd2b3f05ba2bc3775012d/.heroku/node/lib/node_modules/npm/node_modules/cmd-shim/index.js: Legacy octal literals are not allowed in strict mode (166:15)
  164 | function chmodShim (to, cb) {
  165 |   var then = times(2, cb, cb)
> 166 |   fs.chmod(to, 0755, then)
      |                ^
  167 |   fs.chmod(to + ".cmd", 0755, then)
  168 | }
  169 | 
    at Parser.raise (/tmp/build_3a8af19f4cfbd2b3f05ba2bc3775012d/node_modules/@babel/parser/lib/index.js:3851:17)
    at Parser.readNumber (/tmp/build_3a8af19f4cfbd2b3f05ba2bc3775012d/node_modules/@babel/parser/lib/index.js:4702:14)
    at Parser.getTokenFromCode (/tmp/build_3a8af19f4cfbd2b3f05ba2bc3775012d/node_modules/@babel/parser/lib/index.js:4474:14)
    at Parser.nextToken (/tmp/build_3a8af19f4cfbd2b3f05ba2bc3775012d/node_modules/@babel/parser/lib/index.js:4049:12)
    at Parser.next (/tmp/build_3a8af19f4cfbd2b3f05ba2bc3775012d/node_modules/@babel/parser/lib/index.js:3989:10)
    at Parser.eat (/tmp/build_3a8af19f4cfbd2b3f05ba2bc3775012d/node_modules/@babel/parser/lib/index.js:3994:12)
    at Parser.expect (/tmp/build_3a8af19f4cfbd2b3f05ba2bc3775012d/node_modules/@babel/parser/lib/index.js:5153:10)
    at Parser.parseCallExpressionArguments (/tmp/build_3a8af19f4cfbd2b3f05ba2bc3775012d/node_modules/@babel/parser/lib/index.js:6106:14)
    at Parser.parseSubscript (/tmp/build_3a8af19f4cfbd2b3f05ba2bc3775012d/node_modules/@babel/parser/lib/index.js:6016:29)
    at Parser.parseSubscripts (/tmp/build_3a8af19f4cfbd2b3f05ba2bc3775012d/node_modules/@babel/parser/lib/index.js:5935:19)
  pos: 4390,
  loc: Position { line: 166, column: 15 },
  code: 'BABEL_PARSE_ERROR' }
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! banka@1.0.0 build: `rm -rf ./dist && mkdir dist && babel . --out-dir dist`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the banka@1.0.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR!     /tmp/npmcache.zXFlw/_logs/2019-04-19T07_15_46_065Z-debug.log
-----> Build failed

1 个答案:

答案 0 :(得分:2)

错误似乎是由于我的构建脚本中的.标志告诉babel转换我的node_modules文件夹,即使使用--ignore node_modules标志也由于某些尚不明确的原因而拒绝为我工作。我必须重组整个文件夹,才能将node_modules文件夹移到babel脚本的范围之外,以使其最终正常运行