尝试在Heroku上构建应用程序时发生Babel Parser错误 [英] Babel Parser Error on attempting to build app on Heroku

查看:151
本文介绍了尝试在Heroku上构建应用程序时发生Babel Parser错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am attempting to deploy my node js app to Heroku but it keeps failing.

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

I have already set NPM_CONFIG_PRODUCTION=false. Build script works fine on my local machine

这是我的package.json文件

This is my package.json file

"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上遇到的错误

Build should be successful but this is the error I get on 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

推荐答案

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

It seems the error was due to the . flag in my build script telling babel to transpile my node_modules folder, even using the --ignore node_modules flag refused to work for me for some yet to be understood reason. I had to restructure my entire folder to move my node_modules folder beyond the scope of my babel script to finally make it function properly

这篇关于尝试在Heroku上构建应用程序时发生Babel Parser错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆