使用 babel-loader 但 Object.assign 不是函数

use babel-loader but Object.assign is not a function

{ test: /\.js$/, exclude: /node_modules/, loader: 'babel-loader?optional[]=runtime'}

我安装了 babel-runtime

我在上面使用带有 babel-loader 配置的 webpack,但是 get Object.assign 不起作用。我该如何解决?

如果您只使用 babel 作为加载程序,它应该可以工作:

{ test: /\.js$/, exclude: /node_modules/, loader: 'babel'}

您需要安装 babel-runtime。

npm install babel-runtime --save-dev

然后你可以在你的 webpack 配置中使用以下作为加载器 -

{
  test: /\.js?$/,
  exclude: /node_modules/,
  loaders: ['babel?optional=runtime']
}

{
  test: /\.js?$/,
  exclude: /node_modules/,
  loader: 'babel-loader?optional=runtime'
}