electron / forge

:electron: A complete tool for building and publishing Electron applications
https://electronforge.io
MIT License
6.33k stars 492 forks source link

Can't bootstrap Aurelia #3146

Open vilnytskyi opened 1 year ago

vilnytskyi commented 1 year ago

Pre-flight checklist

Electron Forge version

6.0.4

Electron version

22.0.3

Operating system

Windows 11 x64

Last known working Electron Forge version

No response

Expected behavior

The aurelia-bootstrapper@latest npm package should properly bootstrap Aurelia app in required conditions are met.

Actual behavior

Aurelia Bootstrapper tries to resolve aurelia-loader-webpack module from <projectRoot>\.webpack\renderer\native_modules but fails.

Steps to reproduce

  1. Create a new Electron app using npm init electron-app@latest aurelia-app -- --template=webpack-typescript
  2. Open src/index.ts file and add nodeIntegration: true, contextIsolation: false to webPreferences config of BrowserWindow:
    const mainWindow = new BrowserWindow({
    height: 600,
    width: 800,
    webPreferences: {
      nodeIntegration: true,
      contextIsolation: false,
      preload: MAIN_WINDOW_PRELOAD_WEBPACK_ENTRY,
    },
    })
  3. Install aurelia bootstrapper package:
    npm install aurelia-bootstrapper
  4. Import the installed package in src/renderer.ts:
    import 'aurelia-bootstrapper'
  5. Run the application:
    npm run start

Additional information

The following scenario works just fine when running development webpack bundle without Electron.

johannesgiani commented 1 year ago

According to the documentation of aurelia-bootstrapper this package is meant to be used in a browser environment (see Platform Support). Did you try to use it without nodeIntegration: true/contextIsolation: false?

vilnytskyi commented 1 year ago

@johannesgiani yeah, in this case, it complains about the inability to find the require function.

vilnytskyi commented 1 year ago

In fact, the current issue I stopped inspecting is strange webpack module identifiers in webpack runtime registry. When using default simple webpack config without electron-forge, it registers npm packages as:

'aurelia-framework': () => module,
'aurelia-logging': () => module,
...

But for some reason webpack under forge's control registers them like:

'./node_modules/aurelia-framework/dist/index.js?someHashParams': () => module,
'./node_modules/aurelia-logging/dist/index.js?someHashParams': () => module,
...

And that's the reason aurelia-loader-webpack fails to resolve these dependencies during bootstrap stage, as it has hard-coded dependencies name usages like loader.loadModule('aurelia-framework') which then resolves to __webpack_require__('aurelia-framework') that obviously won't work with the way modules are registered, as showcased above.