无法解析模块babel-preset-es2017 / polyfill

时间:2016-09-08 15:57:47

标签: webpack babeljs

当我尝试使用带有es2017的webpack运行我的应用时出现以下错误:

ERROR in ./app/app.js
Module not found: Error: Cannot resolve module 'babel-preset-es2017/polyfill' in C:\Users\mjarn\WebstormProjects\zombie-cat-production\app
 @ ./app/app.js 3:0-39

我的网站设置:

module: {
    loaders: [
      {
        test: /\.js$/,
        loader: 'babel',
        exclude: /node_modules/,
        include: __dirname,
        query: {
          presets: ['es2015', 'es2017', 'react'],
          plugins: ['transform-runtime', 'transform-decorators-legacy', 'transform-class-properties'],
        }
      }
    ]
}

我的输入文件导入语句:

import 'babel-preset-es2017/polyfill'

import React from 'react'
import ReactDOM from 'react-dom'
...

如何让它发挥作用?

2 个答案:

答案 0 :(得分:1)

答案 1 :(得分:0)

官方README已过期。我决定在我的stage-0文件中添加预设.babelrc

{
  "presets": ["es2015", "stage-0", "react"],
  "env": {
    "test": {
      "plugins": [ "babel-plugin-rewire" ]
    }
  }
}

我的webpack.config保持原样。

module: {
  loaders: [
    {
      test: /\.js$/,
      loader: 'babel',
      exclude: /node_modules/,
      include: __dirname
    }
  ]
}