gpt4 book ai didi

node.js - 尝试在 Heroku 上构建应用程序时出现 Babel 解析器错误

转载 作者:搜寻专家 更新时间:2023-10-31 23:50:05 24 4
gpt4 key购买 nike

我正在尝试将我的 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

最佳答案

似乎错误是由于我的构建脚本中的 . 标志告诉 babel 转换我的 node_modules 文件夹,即使使用 --ignore node_modules 标志也拒绝工作对我来说有一些尚待理解的原因。我不得不重组我的整个文件夹,将我的 node_modules 文件夹移到我的 babel 脚本的范围之外,最终使其正常运行

关于node.js - 尝试在 Heroku 上构建应用程序时出现 Babel 解析器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55758607/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com