question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Couldn't find preset "env" relative to directory

See original GitHub issue
  • I have read the contribution documentation for this project.
  • I agree to follow the code of conduct that this project follows, as appropriate.
  • I have searched the issue tracker for an issue that matches the one I want to file, without success.

Please describe your issue: I’m trying to dynamically require an external node_module that is located in /Users/name/plugin due to babel-env (I guess) I’m getting the error stated below.

Is there a way to ignore everything outside of the actual project? I have tried using the ignore option with all possible options but they seem to be ignored.

"ignore": [
          "plugins/**/*.js",
          "/Users/name/plugins/**/*.js"
          ...
        ]

Console output when you run electron-forge

Error: Couldn't find preset "env" relative to directory "/Users/name/plugin/7ada6103-7315-4c24-93f3-4a3a6a0fa7ee"
    at /Users/name/project/node_modules/babel-core/lib/transformation/file/options/option-manager.js:293:19
    at Array.map (native)
    at OptionManager.resolvePresets (/Users/name/project/node_modules/babel-core/lib/transformation/file/options/option-manager.js:275:20)
    at OptionManager.mergePresets (/Users/name/project/node_modules/babel-core/lib/transformation/file/options/option-manager.js:264:10)
    at OptionManager.mergeOptions (/Users/name/project/node_modules/babel-core/lib/transformation/file/options/option-manager.js:249:14)
    at OptionManager.init (/Users/name/project/node_modules/babel-core/lib/transformation/file/options/option-manager.js:368:12)
    at File.initOptions (/Users/name/project/node_modules/babel-core/lib/transformation/file/index.js:216:65)
    at new File (/Users/name/project/node_modules/babel-core/lib/transformation/file/index.js:139:24)
    at Pipeline.transform (/Users/name/project/node_modules/babel-core/lib/transformation/pipeline.js:46:16)
    at BabelCompiler.compileSync (/Users/name/project/node_modules/electron-compilers/lib/js/babel.js:76:26)

contents of .compilerc

{
  "env": {
    "development": {
      "application/javascript": {
        "presets": [
          [
            "env",
            {
              "targets": {
                "electron": "1.4.15"
              }
            }
          ],
          "react"
        ],
        "plugins": [
          "transform-decorators-legacy",
          "transform-flow-strip-types",
          "transform-class-properties",
          "transform-async-to-generator"
        ],
        "sourceMaps": "inline"
      }
    },
    "production": {
      "application/javascript": {
        "presets": [
          [
            "env",
            {
              "targets": {
                "electron": "1.4.15"
              }
            }
          ],
          "react"
        ],
        "plugins": [
          "transform-decorators-legacy",
          "transform-flow-strip-types",
          "transform-class-properties",
          "transform-async-to-generator"
        ],
        "sourceMaps": "none"
      }
    }
  }
}

Please provide either a failing minimal testcase (with a link to the code) or detailed steps to reproduce your problem. Using electron-forge init is a good starting point, if that is not the source of your problem.

Use a clean project (electron-forge init) and try to import any random module from a folder that is not within module.paths


UPDATE: I’ve filed this issue on babel/babel-preset-env#186

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
MarshallOfSoundcommented, Mar 3, 2017

As a temporary workaround for your usecase you could just drop down to babel-preset-es2015

2reactions
adlkcommented, Mar 3, 2017

@MarshallOfSound one thing I did forget to mention. It works if I write:

"presets": [
          [
            "/Users/name/project/node_modules/babel-preset-env",
            {
              "targets": {
                "electron": "1.4.15"
              }
            }
          ],
          "/Users/name/project/node_modules/babel-preset-react"
        ],

But that way, it’s hard to properly collaborate on this project.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Couldn't find preset "env" relative to directory - Stack Overflow
Many of the github issues relating to this suggest that babel-preset-env is not installed. Indeed it doesn't seem to be there in your ......
Read more >
Couldn't find preset "@babel/env" relative to directory #6838
I'm expecting the code to compile (transform) through babel. Current Behavior. Instead I get following error: Error: Couldn't find preset "@ ...
Read more >
Error: Couldn't find preset "@babel/preset-env" relative to ...
Hi, I'm trying to run the project locally on my Windows machine. Unfortunately, v-click-outside is trying to resolve preset ...
Read more >
Error couldn't find preset "env react" relative to directory - Reddit
Hi I'm getting this error and I'm using babel 6.24 version and not using webpack or any module bundler for that matter.
Read more >
[Solved]-Couldn't find preset "env" relative to directory-babel.js
Basically, this type of error occurs due to mismatch in versions of babel-core, babel-preset-env and babel-loader. Below are matched and tested ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found