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

How to indicate that a loader uses ES modules #61

Closed
morganney opened this issue Sep 5, 2021 · 3 comments · Fixed by morganney/magic-comments-loader#18
Closed

How to indicate that a loader uses ES modules #61

morganney opened this issue Sep 5, 2021 · 3 comments · Fixed by morganney/magic-comments-loader#18

Comments

@morganney
Copy link

morganney commented Sep 5, 2021

How do you indicate via config or options that a loader should be loaded using import instead of require?

How do you get this logic to kick-in?

I have a loader that is written with ES modules, and my package.json specifies "type": "module". I am running Jest using the node option --experimental-vm-modules and my tests written with ES modules are all working fine except for this one which has the following error: NonErrorEmittedError: (Emitted value instead of an instance of Error) Error: Must use import to load ES Module.

Relevant stack trace:

      at processResult (node_modules/webpack/lib/NormalModule.js:718:12)
      at node_modules/webpack/lib/NormalModule.js:827:5
      at node_modules/loader-runner/lib/LoaderRunner.js:399:11
      at node_modules/loader-runner/lib/LoaderRunner.js:185:11
      at loadLoader (node_modules/loader-runner/lib/loadLoader.js:33:11)
      at iteratePitchingLoaders (node_modules/loader-runner/lib/LoaderRunner.js:182:2)
      at runLoaders (node_modules/loader-runner/lib/LoaderRunner.js:397:2)
      at NormalModule.doBuild (node_modules/webpack/lib/NormalModule.js:781:3)
      at NormalModule.build (node_modules/webpack/lib/NormalModule.js:928:15)
@morganney
Copy link
Author

morganney commented Sep 6, 2021

Looks like the loader must use the .mjs file extension: https://github.com/webpack/loader-runner/blob/master/test/runLoaders.js#L616

Ok, so it is not possible yet: 4f91458#r40502100

@IdeaHunter
Copy link

@sokra Hi!
You mentioned in discussion here that this is not possible with webpack yet. Can you please elaborate why and what possibly should be done to change that?

@alexander-akait
Copy link
Member

webpack/webpack#13233

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

Successfully merging a pull request may close this issue.

3 participants