我正在构建使用ES6导入的Nodejs应用程序(特别是不和谐的bot),因此我使用Babel生成了生产版本。这些是命令:
"build": "rimraf dist && babel . -d dist",
"dev": "cross-env NODE_ENV=development nodemon --exec babel-node bot.js",
"start": "npm run build && node dist/bot.js",
我在本地运行npm start
,一切正常。但是,此错误在部署期间不断弹出:
[BABEL] Note: The code generator has deoptimised the styling of /tmp/build_f56846a9692bd8d758b406868ccb0544/.heroku/node/lib/node_modules/npm/node_modules/ajv/dist/regenerator.min.js as it exceeds the max of 500KB.
{ SyntaxError: /tmp/build_f56846a9692bd8d758b406868ccb0544/.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_f56846a9692bd8d758b406868ccb0544/node_modules/@babel/core/node_modules/@babel/parser/lib/index.js:3851:17)
at Parser.readNumber (/tmp/build_f56846a9692bd8d758b406868ccb0544/node_modules/@babel/core/node_modules/@babel/parser/lib/index.js:4702:14)
at Parser.getTokenFromCode (/tmp/build_f56846a9692bd8d758b406868ccb0544/node_modules/@babel/core/node_modules/@babel/parser/lib/index.js:4474:14)
at Parser.nextToken (/tmp/build_f56846a9692bd8d758b406868ccb0544/node_modules/@babel/core/node_modules/@babel/parser/lib/index.js:4049:12)
at Parser.next (/tmp/build_f56846a9692bd8d758b406868ccb0544/node_modules/@babel/core/node_modules/@babel/parser/lib/index.js:3989:10)
at Parser.eat (/tmp/build_f56846a9692bd8d758b406868ccb0544/node_modules/@babel/core/node_modules/@babel/parser/lib/index.js:3994:12)
at Parser.expect (/tmp/build_f56846a9692bd8d758b406868ccb0544/node_modules/@babel/core/node_modules/@babel/parser/lib/index.js:5151:10)
at Parser.parseCallExpressionArguments (/tmp/build_f56846a9692bd8d758b406868ccb0544/node_modules/@babel/core/node_modules/@babel/parser/lib/index.js:6108:14)
at Parser.parseSubscript (/tmp/build_f56846a9692bd8d758b406868ccb0544/node_modules/@babel/core/node_modules/@babel/parser/lib/index.js:6018:29)
at Parser.parseSubscripts (/tmp/build_f56846a9692bd8d758b406868ccb0544/node_modules/@babel/core/node_modules/@babel/parser/lib/index.js:5937:19)
pos: 4390,
loc: Position { line: 166, column: 15 },
code: 'BABEL_PARSE_ERROR' }
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! swifty-bot@1.1.0 build: `rimraf dist && babel . -d dist`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the swifty-bot@1.1.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.jrU9L/_logs/2019-04-21T16_56_28_586Z-debug.log
如果有人想看看,这是我的babel配置:
module.exports = {
presets: [
[
'@babel/preset-env',
{
targets: {
node: 'current',
},
},
],
],
plugins: [
[
'babel-plugin-module-resolver',
{
root: ['.'],
alias: {
'@swifty-bot': './src',
},
},
],
],
ignore: ['node_modules', 'babel.config.js'], // Ignoring itself, otherwise it will get compiled
};
我还尝试使用外部依赖项(无效)和babel本身(未编译为commonjs模块)删除严格模式。我被卡住了,不确定该怎么办。感谢您调查