Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Couldn't find preset "@babel/env" relative to directory #9016

Closed
Pasoul opened this issue Nov 12, 2018 · 4 comments
Closed

Couldn't find preset "@babel/env" relative to directory #9016

Pasoul opened this issue Nov 12, 2018 · 4 comments
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue

Comments

@Pasoul
Copy link

Pasoul commented Nov 12, 2018

Bug Report

Current Behavior

I use webpack to build the js file. The js file import an NPM package。When I run yarn run build,
npm package was error:Couldn't find preset "@babel/env" relative to directory "/Users/username/project/node_modules/jlb-tools"

Input Code

My project's package.json

{
  "dependencies": {
    "jlb-tools": "^0.0.4"
  },
  "devDependencies": {
    "babel-core": "^6.26.3",
    "babel-loader": "7",
    "babel-preset-env": "^1.7.0",
    "babel-preset-stage-0": "^6.24.1",
    "webpack": "^4.25.1",
    "webpack-cli": "^3.1.2"
  },
  "scripts": {
    "build": "webpack --mode development"
  }
}

Babel Configuration (.babelrc, package.json, cli command)

My project's .babelrc

{
	"presets": ["env", "stage-0"]
}

The npm package's .babelrc

{
  "presets": [["@babel/preset-env", { "modules": false }]],
  "env": {
    "test": {
      "plugins": ["istanbul"]
    }
  }
}

Environment

  • Babel version(s):v6.26.3
  • Node/npm version: Node 8.9.10
  • OS: 10.13.5
  • Monorepo [e.g. yes/no/Lerna]
  • How you are using Babel: loader

Additional context/Screenshots

image

@babel-bot
Copy link
Collaborator

Hey @Pasoul! We really appreciate you taking the time to report an issue. The collaborators
on this project attempt to help as many people as possible, but we're a limited number of volunteers,
so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack
community that typically always has someone willing to help. You can sign-up here
for an invite.

@Pasoul
Copy link
Author

Pasoul commented Nov 12, 2018

I change npm package's .babelrc to .babelrc.js,and it work

module.exports = {
  presets: [
    require('@babel/preset-env')
  ]
}

why?

@nicolo-ribaudo
Copy link
Member

It's because Babel 6 only handles .babelrc files. To fix your problem, you should exclude node_modules from your compilation.

@Pasoul
Copy link
Author

Pasoul commented Nov 13, 2018

ok,thanks

@Pasoul Pasoul closed this as completed Nov 13, 2018
@lock lock bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Feb 12, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Feb 12, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue
Projects
None yet
Development

No branches or pull requests

3 participants