S
S
StepanSnigur2019-04-10 20:18:25
npm
StepanSnigur, 2019-04-10 20:18:25

Error: Cannot find module '@babel/preset-env', how to fix?

Hello. I just sat down to learn webpack today and got this error: Error: Cannot find module '@babel/preset-env'
I've searched all the forums, but nothing helped.
Here is the babel code:

{
    presets: [
        "@babel/preset-env",
        "stage-3"
    ]
}

Here is the webpack config code:
let path = require('path');
let conf = {
    entry: './src/index.js',
    output: {
        path: path.resolve(__dirname, './dist'),
        filename: 'main.js',
        publicPath: 'dist/'
    },
    devServer: {
        overlay: true
    },
    module: {
        rules : [
            {
                test: /\.js$/,
                loader: 'babel-loader'
            }
        ]
    }
}

module.exports = conf;

Here is package.json:
{
  "name": "webpack-sandbox.ru",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "dev": "webpack-dev-server --mode development --open",
    "build": "webpack --mode production"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "babel-core": "^6.26.3",
    "babel-loader": "^8.0.5",
    "babel-preset-env": "^1.7.0",
    "babel-preset-stage-3": "^6.24.1",
    "babel-upgrade": "^1.0.1",
    "path": "^0.12.7",
    "webpack": "^4.29.6",
    "webpack-cli": "^3.3.0",
    "webpack-dev-server": "^3.3.1"
  },
  "dependencies": {
    "@babel/core": "^7.4.3"
  }
}

Thank you in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
StepanSnigur, 2019-04-11
@StepanSnigur

After updating babel, you should delete preset-env altogether, because. In version 7, it was completely abandoned.
Here is the Babel file code for version 7:

{
    presets: [
        "@babel/preset-env"
    ]
}

Here are all the dependencies:
{
  "name": "webpack-sandbox.ru",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "build": "webpack --mode production",
    "dev": "webpack-dev-server --mode development --open"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "@babel/core": "^7.4.3",
    "@babel/preset-env": "^7.4.3",
    "@babel/preset-stage-3": "^7.0.0", //можно удалить
    "babel-loader": "^8.0.0-beta.6",
    "babel-preset-stage-3": "^6.24.1", //можно удалить
    "css-loader": "^2.1.1",
    "path": "^0.12.7",
    "style-loader": "^0.23.1",
    "webpack": "^4.29.6",
    "webpack-cli": "^3.3.0",
    "webpack-dev-server": "^3.3.1"
  }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question