Cannot resolve babel-preset-es2017 / polyfill module

When I try to run my application using webpack with es2017, I get the following error:

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

My webpack setup:

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 file input operations:

import 'babel-preset-es2017/polyfill'

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

How can I make it work?

+4
source share
2 answers

The official README is deprecated. I decided to add a preset stage-0to the file instead .babelrc.

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

My webpack.configstayed as it is.

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

Source: https://habr.com/ru/post/1654041/


All Articles