How to indicate that a loader uses ES modules
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)
~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: https://github.com/webpack/loader-runner/commit/4f91458eca03c7350971e0c555521f4e6c13c6e0#r40502100
@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?
https://github.com/webpack/webpack/issues/13233