【发布时间】:2019-12-15 06:37:45
【问题描述】:
我正在尝试配置我的 NodeJs 项目。如果我在代码中添加任何 async/await,则会出现以下错误:
1] import _Object$defineProperty from "../../core-js/object/define-property";
[1] ^^^^^^^^^^^^^^^^^^^^^^
[1]
[1] SyntaxError: Unexpected identifier
我的.babelrc:
{
"presets": [
[
"@babel/preset-env",
{
"targets": {
"node": true
},
}
]
],
"plugins": ["@babel/plugin-transform-regenerator"]
}
我的 webpack.config.js 是
const path = require("path")
const nodeExternals = require("webpack-node-externals")
const config = {
entry: "./src/index.js",
target: "node",
externals: [nodeExternals()], // in order to ignore all modules in node_modules folder
output: {
filename: "[name].js",
publicPath: "/client/dist/",
chunkFilename: "[name].bundle.js",
path: `${__dirname}/client/dist`
},
module: {
rules: [
{
test: /\.(js)$/,
exclude: ["node_modules/"],
include: [/src/],
use: {
loader: "babel-loader"
},
plugins: ["@babel/plugin-transform-runtime"]
},
{
test: /\.(woff2?|eot|ttf|otf)$/,
loader: "file-loader",
options: {
limit: 10000,
name: "[name].[hash:7].[ext]"
}
}
]
},
watch: true
}
module.exports = config
我尝试添加@babel/plugin-transform-runtime,但它并没有解决我的问题。 谁能给我线索,我做错了什么?
提前致谢
【问题讨论】: