Fuse-box: require('electron') generates code with a syntax error

Created on 20 Feb 2017  路  5Comments  路  Source: fuse-box/fuse-box

I need to use functionality provided by the electron package (desktopCapturer), but as soon as I add const electron = require('electron') the generated bundle gives this error in Electron: Uncaught SyntaxError: Unexpected token else

Fuse-box: 1.3.118

My fuse.js:

const fsbx = require("fuse-box");
const fuseBox = fsbx.FuseBox.init({
    homeDir: "src/",
    outFile: "./build/out.js",
    plugins: [],
    serverBundle: true,
});
fuseBox.bundle(">index.js");

My index.js:

const electron = require('electron');

This is the bundle: https://gist.github.com/thepatrick/a75abb96ce98e45b513a7b8e88258fc0

Ideally I would actually not have electron bundled in at all, but I haven't found a way to say "hey, just use the require function provided by the environment please"

Waiting for verification discussion required

Most helpful comment

a Docs PR would be great :)

All 5 comments

Hi!
I am no expert with electron, but there are people who might help
https://github.com/fuse-box/fuse-box/issues/212

Here's how you can use to get electron up & running.

Like many of the examples here, I used a vendor bundle and put this in:

{
  shim: {
    electron: { exports: "global.require('electron')" }
  },
  serverBundle: true
}

In your renderer code, you can import { clipboard } from 'electron' like you're used to. No need to target inclusion with +electron or anything like that.

These settings essentially just tell fuse-box to "hold my beer, i got this".

a Docs PR would be great :)

Closing this for now. Please feel free to check the latest bleeding edge version [email protected]
and documentation for it http://fuse-box.org:3333. You are welcome to re-open it elsewise ;-)

Please check the official electron seed https://github.com/fuse-box/fuse-box-electron-seed

Working great on 2.0.0-beta.8.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

miickel picture miickel  路  4Comments

misantronic picture misantronic  路  3Comments

tomitrescak picture tomitrescak  路  4Comments

vegarringdal picture vegarringdal  路  5Comments

freehuntx picture freehuntx  路  3Comments