Electron-forge: Couldn't find preset "env" relative to directory

Created on 3 Mar 2017  路  9Comments  路  Source: electron-userland/electron-forge

  • [x] I have read the contribution documentation for this project.
  • [x] I agree to follow the code of conduct that this project follows, as appropriate.
  • [x] 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

Question

Most helpful comment

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

All 9 comments

It should still resolve the env preset from your local. I'll play around with this and see what I can figure out 馃憤

@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.

@adlk Interesting, this problem is isolated to the env preset. Any other preset works correctly. I think this should be raised on that repository so that they can figure out whats going on

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

@MarshallOfSound ok, thanks. I will create an issue at the babel-preset-env repo!

Link it here for reference when you do 馃槃

I've this same error when I use npm v2, but not npm v4 (haven't tried v3).

My babelrc is

{
  "presets": [
      "env"
  ],
  "plugins": [
      "transform-es2015-modules-umd"
  ]
}

and I am just running

npm install
babel src --out-dir dist

The problem literally doesn't happen if I use npm v4.

So this isn't an electron issue, it's a problem between how babel finds modules when installed with npm v2 vs npm v4.

EDIT: nevermind, for me I was actually missing the module when I nuked node_modules and switched to v2, because I'd forgotten to use --save-dev.

IMO Electron Forge should only support NPM 3 or above. Node 6 (our current minimum requirement) was released in April 2016, NPM 3 (stable) was released in September 2015. NPM 2's dependency resolution is significantly different from modern NPM.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kzimny picture kzimny  路  3Comments

liamdawson picture liamdawson  路  4Comments

partheseas picture partheseas  路  3Comments

Skizu picture Skizu  路  5Comments

Neurrone picture Neurrone  路  4Comments