Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Jest cli suddently has stopped working, all test fails 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"]
    }
  }
}
like image 661
alfredopacino Avatar asked Jun 09 '19 23:06

alfredopacino


People also ask

What is preset ENV in Babel?

@babel/preset-env is a smart preset that allows you to use the latest JavaScript without needing to micromanage which syntax transforms (and optionally, browser polyfills) are needed by your target environment(s). This both makes your life easier and JavaScript bundles smaller!

How do you set up Babel?

Simply add a "scripts" field to your package. json and put the babel command inside there as build . This will run Babel the same way as before and the output will be present in lib directory, only now we are using a local copy. Alternatively, you can reference the babel cli inside of node_modules .

What's Babel for in JavaScript?

Babel is a JavaScript compiler Babel is a toolchain that is mainly used to convert ECMAScript 2015+ code into a backwards compatible version of JavaScript in current and older browsers or environments.

What is Babel RC?

The . babelrc file is your local configuration for your code in your project. Generally you would put it in the root of your application repo. It will affect all files that Babel processes that are in the same directory or in sibling directories of the . babelrc .


1 Answers

you can try this via npm

npm install --save-dev @babel/preset-env
like image 182
kp85 Avatar answered Oct 06 '22 21:10

kp85