[使用webpack和babel以及节点v12.13构建node
api时,出现此错误:
Module build failed (from /../node_modules/babel-loader/lib/index.js):TypeError: /../src/handler.js: Property name expected type of string but got null
这似乎与源文件中的ES6导入语句有关。
下面是我最终得到的配置。基于此,使它起作用的唯一方法是设置{ targets: { node: 6 }}
,但我需要将目标设置为v12。
我还没有找到相关的讨论。这个问题可能是什么原因?这是yarn workspace
中的一个程序包,但我认为这没有关系。
。babelrc :(位于api包根目录中)
comments: false, presets: [ [ '@babel/preset-env', { targets: { node: 'current' } } ] ], plugins: [ '@babel/plugin-transform-runtime', '@babel/plugin-transform-regenerator', '@babel/plugin-transform-modules-commonjs', '@babel/plugin-proposal-object-rest-spread', 'source-map-support' ]
webpack.config.js:
const path = require('path') const nodeExternals = require('webpack-node-externals') const slsw = require('serverless-webpack') const webpack = require('webpack') module.exports = { entry: slsw.lib.entries, target: 'node', mode: slsw.lib.webpack.isLocal ? 'development' : 'production', optimization: { minimize: false }, performance: { hints: false }, devtool: slsw.lib.webpack.isLocal ? 'eval-source-map' : 'none', externals: [ nodeExternals({ whitelist: ['workspace-package-b'] }), nodeExternals({ modulesDir: path.resolve(__dirname, '../../node_modules'), whitelist: ['workspace-package-b'] }) ], module: { rules: [ { test: /\.graphql$/, loader: 'graphql-tag/loader' }, { test: /\.js$/, exclude: /node_modules/, use: ['imports-loader?graphql', 'babel-loader'] } ] }, output: { libraryTarget: 'commonjs2', path: path.join(__dirname, '.webpack'), filename: '[name].js', sourceMapFilename: '[file].map' }, plugins: [new webpack.DefinePlugin({ 'global.GENTLY': false })] }
相关的package.json:
(dependencies)
"babel-runtime": "^6.26.0",
"core-js": "^3.6.4",
(devDependencies)
"@babel/core": "^7.9.0",
"@babel/plugin-proposal-object-rest-spread": "^7.4.4",
"@babel/plugin-transform-modules-commonjs": "^7.9.0",
"@babel/plugin-transform-regenerator": "^7.8.7",
"@babel/plugin-transform-runtime": "^7.9.0",
"@babel/preset-env": "^7.9.0",
"babel-jest": "24.9.0",
"babel-loader": "8.1.0",
"babel-plugin-source-map-support": "^2.0.1",
"jest": "24.9.0",
"webpack": "4.19.1",
"webpack-node-externals": "^1.7.2"
[使用webpack和babel以及节点v12.13构建节点api时,出现此错误:模块构建失败(来自/../node_modules/babel-loader/lib/index.js):TypeError:/。 ./src/handler.js:属性...
.babelrc
配置文件的形式已被弃用,而不是使用那个形式的babeljs建议babel.config.js
,如果您想这样称呼它,则使用此“表单”,有一个很酷的功能。您将获得一个可以使用很多技巧的参数。