esm icon indicating copy to clipboard operation
esm copied to clipboard

Not working with renderer process for Electron 6 or newer

Open aistrych opened this issue 5 years ago • 3 comments

After upgrading electron and esm versions to the newest ones (in https://github.com/standard-things/electron-quick-start) esm loader for renderer process stopped working with errors:

"Uncaught /path_to_my_project_dir/electron-quick-start/index.html:1 Error: Cannot find module './renderer.js' Require stack:

  • electron/js2c/renderer_init at file:///path_to_my_project_dir/electron-quick-start/index.html:17:7"

Requiring module from node_modules like this:

<script>
  // You can also require other files to run in this process
  require = require('esm')(module)
  require('electron')
</script>

works without issues.

Here are my changes for electron 8 (but issue exists for electron 6 and 7 as well): https://github.com/Astrych/electron-quick-start/commit/9ca5498beacf08d1572ffee05df385faad261dd0

With electron 4 and 5 everything works just fine.

aistrych avatar Feb 12 '20 09:02 aistrych

I worked it around with this

      module.id = '.';
      module.path = '.';
      require = require('esm')(module);
      require('./renderer.js')

but when I imported openlayers, stranges thing happened. it works on the first load, but fails after reload (by menu). If I keep reloading again and again, it will work, fail, work, fail, work, fail....

Update: I made it work always by disabling cache.

toddwong avatar Mar 21 '20 16:03 toddwong

Christ, any one figure this one out? I'm running out of ideas

kylewetton avatar Jun 03 '20 08:06 kylewetton

I have same issue, anyone found a solution or workaround for this issue?

veeramarni avatar Mar 08 '21 14:03 veeramarni