Module imports without extension fail loading
See original GitHub issueI’ve configured regarding the documentation as follows
karma.config.js
files: [
{ pattern: 'test/**/*.js', type: 'module' },
{ pattern: 'src/**/*.js', type: 'module', included: false }
],
Then when using a working mocha test with imports without .js extensions, like
import TestModule from '../../src/TestModule';
…the execution with karma fails with:
...
26 05 2021 15:09:57.267:WARN [web-server]: 404: /base/src/TestModule
Chrome Headless 90.0.4430.212 (Mac OS 10.15.7) ERROR
Uncaught Error loading test/Test.js
at http://localhost:9876/context.html:286:271
Importing ‘…/…/src/TestModule.js’ does work, but is not a solution as the TestModule.js itself imports without extensions. The implementation of TestModule.js shall not be changed.
Is this a bug in Karma runner or did a missed an important configuration here? Help appreciated
Issue Analytics
- State:
- Created 2 years ago
- Comments:5
Top Results From Across the Web
How does JavaScript import find the module without an ...
In Node.js versions which support ESM, the runtime will not search for extensions, but it will resolve modules from node_modules by name.
Read more >CommonJS modules | Node.js v19.3.0 Documentation
Attempting to do so will throw a ERR_REQUIRE_ESM error. Use import() instead. The .mjs extension is reserved for ECMAScript Modules which cannot be...
Read more >Dynamic module import doesn't work in webextension content ...
Hi, maybe I'm doing something wrong, but I'm not able to import a module in a webextension content script via the dynamic import....
Read more >Module Methods - webpack
The ES2015 Loader spec defines import() as method to load ES2015 modules dynamically on ... It is not possible to use a fully...
Read more >Documentation - Module Resolution - TypeScript
We'll cover non-relative imports next. Finally, if the compiler could not resolve the module, it will log an error. In this case, the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Seems to work as intended: https://stackoverflow.com/a/55289496/1377864
Unless you told it to do so, Karma will not do any file processing, so it will just load the file “as is” in the browser.
No, there is no way to do it without plugins. Vanilla Karma just loads your JS code in the browser without any extra processing and therefore JS should be in the format which the browser understands.