-
-
Notifications
You must be signed in to change notification settings - Fork 158
Couldn't find preset "env" relative to directory #186
Comments
@adlk which |
It sounds like you have no installed |
@loganfsmyth I got this issue earlier today using |
As suggested by @loganfsmyth installing |
@JPeer264 tried it with the latest version of it's not the greatest workaround but it works for now if I use absolute paths in my compilerc for my presets:
|
@adlk hm strange - are you using babel as cli? |
@JPeer264 yup |
I seem to be having the same problem. I am also using electron-forge and I am trying to include a package that is not in node_modules. I have tried all the above suggestions and the only thing that works is what @adlk suggested. I looked in node_modules/babel-core/package.json and it says also happens if I npm link to a repo that is not in the path. Instead of using npm link I have to manually copy the external module into my node_modules directory to get it to work. |
I can confirm that I get this problem when using npm v2, but no problems when using v4. duplicate: #219 You can reproduce with this simple babelrc: {
"presets": [
"env"
],
"plugins": [
"transform-es2015-modules-umd"
]
} make a simple js file in npm install -g "npm@^2"
npm install babel-cli babel-preset-env babel-plugin-transform-es2015-modules-umd
./node_modules/.bin/babel src -d dist That will cause the error. Then, if you update to npm v4, the error will go away. |
@trusktr hmm that's weird. I'm running |
Same error for me, same line and column number, when using npm v2. Here's a physical repro: https://github.com/trusktr/tween.js/tree/ddba437d51b8af9d4f1b84dec4ca4533e0a4d09e You can clone that and checkout that commit, then just run |
@adlk I'm not getting the error with npm v4.4 |
@adlk Hmmm, something is fishy, I was on npm v4, and I was able to run babel just fine with no errors just a moment ago, but now I can not. Investigating... |
Yep, I've just updated to the latest npm version and I'm still getting the error :( |
Oh, oops, I accidentally deleted So, it is working for me with npm v4.4 and a fresh install. I just double checked (each time I deleted node_modules, and ran |
Great! I'll do some tests and will get back to you asap. |
Ah, false alarm, I forgot to use So, it was due to the package actually missing. It works for me on npm v2 and v4 right now. I would be glad to check yours out. Can you can push it somewhere? |
Running into the same issue for my project where I have other modules npm linked. Same issue if I just tell webpack to resolve them from their project folders directly. |
@yavorsky - #219 (comment) , |
@ericnkatz Good! But did it work for you just with @adlk Did you have success with changes according to #186 (comment)? |
@yavorsky in my case the package does not actually use babel at all so I don't add it to the For clarity
Solution was to cd to Forked Module and install babel-env-preset even though the module itself doesn't need or use it (although for team members I may have to add this to package.json and just remember to remove when I PR back) |
This is annoying I'm using babel as part of a build system that can be used either globally or locally, as a result of this I have to do more messing around and construct the node_modules path for babel: const mod = (__dirname.includes(process.cwd()) ? process.cwd() : __dirname) + '/node_modules/';
// ...
.pipe(plugin.babel({presets: [[mod + 'babel-preset-env']]})) Does anyone have an explanation for how this makes sense? plugins are probably always node modules, why make them relative to the input source? and for the cases when they aren't source relative paths could still be checked. |
In Babel 7.x, plugins and presets will be resolved relative to the cwd rather than relative to the file. We agree the current behavior is not something anyone wants. |
Excellent, good news, thanks @loganfsmyth 😄 |
@ThomasBrierley do you mind if we close this? This breaking change is also in the upgrade guide. |
I'd say it's ok to close, however @adlk originated this issue not me. |
came to the same issue because of the documentation for the CLI option is missing the |
I ran into the problem as well, everything was working fine when I were developing on project X normally. However, as soon as I did "npm link foo" inside X, then the build would fail there with the error: Module build failed: Error: Couldn't find preset "es2015" relative to directory "/path/to/project/foo" The workaround that fixed it for me was to install all presets from "project X" into project "foo" (without --save or changing the package.json). In my case those were: npm install babel-preset-es2015 babel-preset-react babel-preset-react-hmre So I didn't even have babel-preset-env install in any of my project; the the bug is in babel itself. Hopefully it will be fixed in babel7 like @loganfsmyth said. |
The cleanest workaround to this problem is probably to prefix all the presets with "babel-preset-" and then do
This is explained here: |
@loganfsmyth thankyou your answers is very helpful for me;my english is very poor ; haha |
Along with fixing the entry point path, babel-preset-env has to be installed in order for `npm link` to work with cfgov-refresh due to the below babel bug. babel/babel-preset-env#186
make sure you clear node_modules, use a later npm version. I'm having a really hard time understanding all these issues/errors so closing (make a new issue, or better just ask in slack)
|
It works for me,modify file ".babelrc": |
I resolved this error by first creating a .babelrc file with the following contents in the project root folder:
I then ran the following command to install this development dependency and save it to the package.json
|
This is still an issue when using babelify with the option Cross-reference: babel/babelify#134 |
Run: |
I'm working with the
electron-forge
setup and I'm trying to dynamically require an external node_module that is located in/Users/name/plugin
Unfortunately babel-preset-env is trying to resolve the preset relative to the required module instead of the local module.Console output when trying to require the module
contents of .compilerc
How to test this issue:
Use a clean project (
electron-forge init
) and try to import any random module from a folder that is not withinmodule.paths
The text was updated successfully, but these errors were encountered: