alfredopacino
alfredopacino

Reputation: 3241

Cannot find module 'babel-preset-env' from PATH Did you mean "@babel/env"?

Just cli suddently has stopped working, all test fail with:

Cannot find module 'babel-preset-env' from '/PATH'
    - Did you mean "@babel/env"?

I'm sure it is some kind of incompatibility between a module which uses babel 6 and my project with babel 7, but I'm not sure how can I solve.

This is package.json

{
  "name": "testing101",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "parcel index.html",
    "test": "jest src/*.js --watchAll",
    "nyc": "nyc ava",
    "build": "babel src/*.js -d dist"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "@babel/core": "^7.4.5",
    "@babel/preset-env": "^7.4.5",
    "@types/jest": "^24.0.13",
    "jest": "^24.8.0",
    "nyc": "^14.1.1",
    "parcel-bundler": "^1.7.0"
  },
  "jest": {
    "verbose": true,
    "testURL": "http://localhost:1234/",
    "collectCoverage": true
  },
  "dependencies": {
    "axios": "^0.18.0",
    "nock": "^10.0.6"
  }
}

This is .babelrc

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

Upvotes: 31

Views: 68316

Answers (6)

BrunoMatosDev
BrunoMatosDev

Reputation: 11

i had the same error.. The Eslint was going crazy, this worked for me :

{
  "extends": ["@sanity/eslint-config-studio", "@babel/core"],
  "parser": "@babel/eslint-parser",
  "parserOptions": {
    "requireConfigFile": false,
    "babelOptions": {
      "presets": ["@babel/preset-env"]
    }
  }
}

Upvotes: 1

Anthony Accioly
Anthony Accioly

Reputation: 22461

In the test section of the .babelrc file you have accidentally used an unscoped preset ("presets": ["env"]). This used to be the way to do it before Babel 7 and the @babel scope. More than that, since you are already configuring @babel/preset-env as a global preset, you don't need to define it again for the test environment. Removing the entire test environment configuration as below should fix your problem:

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

Upvotes: 48

Rajeshwar Sharma
Rajeshwar Sharma

Reputation: 31

I was having the same issue with ReactJS project built using Sanity. I added the below code to .eslintrc

{
  "extends": ["@sanity/eslint-config-studio", "@babel/core"]
}

Upvotes: 2

Huy
Huy

Reputation: 822

This worked for me:

.babelrc

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

.eslintrc (add @babel/core to the existing list of configs)

{
  "extends": ["@babel/core", ...EXISTING-CONFIGS-HERE]
}

Upvotes: 8

Siwei
Siwei

Reputation: 21549

I met this problem when I opened 2 terminal with 2 different versions of node. ( I installed NVM to use different versions of nodes )

  • terminal 1: npm install ( correct, this is node 14 )
  • terminal 2: npm run dev ( error, this is node 16 )

so the solution is quite simple:

  1. remove the node_modules
  2. run npm install and npm run dev with the same node version.

Upvotes: 2

kp85
kp85

Reputation: 441

you can try this via npm

npm install --save-dev @babel/preset-env

Upvotes: 30

Related Questions