Electron-forge: [5.x] Cannot get spread operators working (Error: Requires Babel "^7.0.0-0", but was loaded with "6.26.3")

Created on 3 Nov 2018  Â·  1Comment  Â·  Source: electron-userland/electron-forge

I'm trying to transition my electron app to electron-forge because I thought it would make things easier. I can't get spread operators working though, despite adding "@babel/plugin-proposal-object-rest-spread" to .compilerc. I'm hoping this is just because I'm new to configuring babel.

The most widespread solution I can find is to add the plugin I mentioned before, but I think electron-compile is trying to use Babel and 6 and I can't figure out how to change that.

my app here https://github.com/kkitay/raccoon/tree/raccoon-forge/raccoon-forge

The boilerplate is from using electron-forge init my-new-project --template=react today.

I get the following error on npm start:
```raccoon-forge $ npm start

[email protected] start /Users/kat/dev/raccoon/raccoon-forge
electron-forge start

✔ Checking your system
✔ Locating Application
✔ Preparing native dependencies
✔ Launching Application
(electron) The 'lstatSyncNoException' function has been deprecated and marked for removal.
(electron) The 'lstatSyncNoException' function has been deprecated and marked for removal.
(electron) The 'lstatSyncNoException' function has been deprecated and marked for removal.
App threw an error during load
Error: Requires Babel "^7.0.0-0", but was loaded with "6.26.3". If you are sure you have a compatible version of @babel/core, it is likely that something in your build process is loading the wrong version. Inspect the stack trace of this errorto look for the first entry that doesn't mention "@babel/core" or "babel-core" to see what is calling Babel.
at throwVersionError (/Users/kat/dev/raccoon/raccoon-forge/node_modules/@babel/helper-plugin-utils/lib/index.js:65:11)
at Object.assertVersion (/Users/kat/dev/raccoon/raccoon-forge/node_modules/@babel/helper-plugin-utils/lib/index.js:13:11)
at _default (/Users/kat/dev/raccoon/raccoon-forge/node_modules/@babel/plugin-proposal-object-rest-spread/lib/index.js:41:7)
at /Users/kat/dev/raccoon/raccoon-forge/node_modules/@babel/helper-plugin-utils/lib/index.js:19:12
at Function.memoisePluginContainer (/Users/kat/dev/raccoon/raccoon-forge/node_modules/babel-core/lib/transformation/file/options/option-manager.js:113:13)
at Function.normalisePlugin (/Users/kat/dev/raccoon/raccoon-forge/node_modules/babel-core/lib/transformation/file/options/option-manager.js:146:32)
at /Users/kat/dev/raccoon/raccoon-forge/node_modules/babel-core/lib/transformation/file/options/option-manager.js:184:30
at Array.map ()
at Function.normalisePlugins (/Users/kat/dev/raccoon/raccoon-forge/node_modules/babel-core/lib/transformation/file/options/option-manager.js:158:20)
at OptionManager.mergeOptions (/Users/kat/dev/raccoon/raccoon-forge/node_modules/babel-core/lib/transformation/file/options/option-manager.js:234:36)
at OptionManager.init (/Users/kat/dev/raccoon/raccoon-forge/node_modules/babel-core/lib/transformation/file/options/option-manager.js:368:12)
at File.initOptions (/Users/kat/dev/raccoon/raccoon-forge/node_modules/babel-core/lib/transformation/file/index.js:212:65)
at new File (/Users/kat/dev/raccoon/raccoon-forge/node_modules/babel-core/lib/transformation/file/index.js:135:24)
at Pipeline.transform (/Users/kat/dev/raccoon/raccoon-forge/node_modules/babel-core/lib/transformation/pipeline.js:46:16)
at BabelCompiler.compileSync (/Users/kat/dev/raccoon/raccoon-forge/node_modules/electron-compilers/lib/js/babel.js:81:26)
at CompilerHost.compileUncachedSync (/Users/kat/dev/raccoon/raccoon-forge/node_modules/electron-compile/lib/compiler-host.js:669:27)
at cache.getOrFetchSync (/Users/kat/dev/raccoon/raccoon-forge/node_modules/electron-compile/lib/compiler-host.js:645:72)
at CompileCache.getOrFetchSync (/Users/kat/dev/raccoon/raccoon-forge/node_modules/electron-compile/lib/compile-cache.js:346:18)
at CompilerHost.fullCompileSync (/Users/kat/dev/raccoon/raccoon-forge/node_modules/electron-compile/lib/compiler-host.js:645:18)
at CompilerHost.compileSync (/Users/kat/dev/raccoon/raccoon-forge/node_modules/electron-compile/lib/compiler-host.js:484:77)
at Object.require.extensions.(anonymous function) [as .js] (/Users/kat/dev/raccoon/raccoon-forge/node_modules/electron-compile/lib/require-hook.js:68:48)
at Module.load (internal/modules/cjs/loader.js:620:32)
at tryModuleLoad (internal/modules/cjs/loader.js:559:12)
at Function.Module._load (internal/modules/cjs/loader.js:551:3)
at Module.require (internal/modules/cjs/loader.js:658:17)


My `.compilerc`:

{
"env": {
"development": {
"application/javascript": {
"presets": [
["env", { "targets": { "electron": "1.6.0" } }],
"react"
],
"plugins": ["transform-async-to-generator", "transform-es2015-classes", "react-hot-loader/babel", "@babel/plugin-proposal-object-rest-spread"],
"sourceMaps": "inline"
}
},
"production": {
"application/javascript": {
"presets": [
["env", { "targets": { "electron": "1.6.0" } }],
"react"
],
"plugins": ["transform-async-to-generator", "transform-es2015-classes", "@babel/plugin-proposal-object-rest-spread"],
"sourceMaps": "none"
}
}
}
}
```

my package.json: https://github.com/kkitay/raccoon/blob/raccoon-forge/raccoon-forge/package.json

Question

Most helpful comment

Unfortunately, I believe in order to use Babel 7 with Electron Forge v5, you'd have to change electron-compile to use Babel 7. At this point I think you have a few options:

  • Use the Babel 6 version of the plugin (from a cursory search, I think it's babel-plugin-transform-object-rest-spread)
  • Update electron-compile to use Babel v7 as mentioned above (if you do so, please submit a PR to that repo so everyone can get that enhancement)
  • Use Electron Forge v6, although I think to get the automatic compilation support you'd either have to use the Electron Compile plugin (which gets you back to the same problem you had before) or the Webpack plugin.

>All comments

Unfortunately, I believe in order to use Babel 7 with Electron Forge v5, you'd have to change electron-compile to use Babel 7. At this point I think you have a few options:

  • Use the Babel 6 version of the plugin (from a cursory search, I think it's babel-plugin-transform-object-rest-spread)
  • Update electron-compile to use Babel v7 as mentioned above (if you do so, please submit a PR to that repo so everyone can get that enhancement)
  • Use Electron Forge v6, although I think to get the automatic compilation support you'd either have to use the Electron Compile plugin (which gets you back to the same problem you had before) or the Webpack plugin.
Was this page helpful?
0 / 5 - 0 ratings