Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic Import Hangs #692

Closed
dsanders11 opened this issue Dec 18, 2018 · 6 comments
Closed

Dynamic Import Hangs #692

dsanders11 opened this issue Dec 18, 2018 · 6 comments
Labels

Comments

@dsanders11
Copy link

@jdalton, sorry if I'm missing something obvious here, trying to get something working for a deadline so can't deep dive.

I can't seem to get import() to do anything in Electron. I have a reproduce case here, but I'll reproduce the code here since it's simple:

import('./foo.js').then(module => {
  console.log('success', module)
}).catch(error => {
  console.error('error', error)
})

I'd expect that to either resolve or reject, but instead neither happens. I've tried a number of different things with no change:

  • File suffix of .mjs
  • Configuring esm to "module": "all"
  • Various combinations of import('foo.js'), import('./foo'), etc

Any pointer in the right direction?

P.S. Can installed package names be used, like import('events')?

@jdalton
Copy link
Member

jdalton commented Dec 18, 2018

Hi @dsanders11!

I can't speak to the failure of promise resolve or reject (I'll need to dig in more), but I can tell you what the issue is outside of that. If you're using .mjs then no esm options apply to it. This means "mode": "all" will not be respected by .mjs files and it will treat .js files as CJS with only a default export. If you're looking for ecosystem interop/support you should use .js instead of .mjs.

@dsanders11
Copy link
Author

Good to know, but .mjs was just one of the various combination I tried to see if I could make the needle move at all.

For the moment I've fallen back to using require() to get a similar effect (but synchronous instead of aync).

@jdalton
Copy link
Member

jdalton commented Dec 18, 2018

Have you tried Electron 3 stable?

@dsanders11
Copy link
Author

@jdalton, yes, I just tried changing that branch to Electron 3 stable, same result.

@jdalton
Copy link
Member

jdalton commented Dec 19, 2018

Thanks for the repro. I narrowed it down to something funky with builtin setImmediate. It looks like something is going wrong in their wrapper:

https://github.com/electron/electron/blob/539d6d20b73a29e363489f4b528eddf22a2a2e47/lib/common/init.js#L33-L34

Update:

It's because I'm using require('timers').setImmediate and Electron wraps window.setImmediate. So I'm missing out on their special wrap.

Update:

Patched b85f671. To see logs in the renderer process you'll want to mainWindow.webContents.openDevTools() from main.js.

@jdalton jdalton added bug and removed question labels Dec 19, 2018
@jdalton jdalton closed this as completed Dec 19, 2018
@dsanders11
Copy link
Author

@jdalton, thanks for the quick fix! I've confirmed in the repro case that it's now acting as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants