Issue with @babel import _Object$defineProperty from "../../core-js/object/define-property";

I am trying to configurate my NodeJs project. If I add any async/await in the code, the following error appears:

1] import _Object$defineProperty from "../../core-js/object/define-property";
[1]        ^^^^^^^^^^^^^^^^^^^^^^
[1] 
[1] SyntaxError: Unexpected identifier

My .babelrc:

{
  "presets": [
    [
      "@babel/preset-env",
      {
        "targets": {
          "node": true
        },
      }
    ]
  ],
  "plugins": ["@babel/plugin-transform-regenerator"]
}

My webpack.config.js is

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

I tried to add @babel/plugin-transform-runtime, but it did not solve my problem. Could somebody give me the clue, what I am doing not right?

Thanks in advance

1 answer

  • answered 2019-12-14 22:37 Mike Abeln

    Try adding babel-polyfill to your project, and as an entry for webpack:

    yarn add babel-polyfill -D

    and in webpack.config.js:

    const path = require("path")
    const nodeExternals = require("webpack-node-externals")
    
    const config = {
      entry: {
        polyfill: "babel-polyfill",
        app: "./src/index.js"
      },
    
    ...