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

Runtime externals don't work in webpack #238

Open
ef4 opened this issue Dec 19, 2022 · 2 comments
Open

Runtime externals don't work in webpack #238

ef4 opened this issue Dec 19, 2022 · 2 comments

Comments

@ef4
Copy link

ef4 commented Dec 19, 2022

Environment

unplugin 1.0.1

Reproduction

https://github.com/ef4/unplugin-bug-repro (edited to add)

Describe the bug

This code:

// If the resolved module does not exist,
// we treat it as a virtual module
if (!fs.existsSync(resolved)) {

tries to locate external modules on the filesystem at build time, and if they're not found it introduces empty virtual modules for them.

But this means we cannot actually use externals the way that both webpack and rollup typically understand externals: they're supposed to get resolved at runtime. Whether they existed during build time is not supposed to matter.

Expected behavior:

  • If my resolveId hook returns false, the original import statement should be left alone in the output, so that it will be resolved at runtime.
  • If my resolveId hook returns { external: true, id: 'xyz' }, the original import statement gets replaced with an import statement for 'xyz', and that redirected import statement will get resolved at runtime.

Actual behavior:

  • In both the above cases, the original import is replaced with an empty virtual module, and no runtime resolution ever happens.

Additional context

No response

Logs

No response

@JerryWu1234
Copy link

Could you provide a duplicate?
I can't debugger

@ef4
Copy link
Author

ef4 commented Mar 20, 2023

Here is a reproduction: https://github.com/ef4/unplugin-bug-repro

It contains both rollup and webpack configs, so you can see that the rollup build works correctly and the webpack build fails at runtime.

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

No branches or pull requests

2 participants