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

2019-08-11 17:41发布

问题:

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

I installed babel-runtime

I use webpack with babel-loader config above, but get Object.assign is not function. How do I fix it?

回答1:

You will need to install babel-runtime.

npm install babel-runtime --save-dev

Then you can use the following as a loader in your webpack config -

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

or

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


回答2:

It should work if you just use babel as the loader:

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