Directory import is not supported resolving ES modules
See original GitHub issuePrerequisites
- I confirm my issue is not in the opened issues
- I confirm the Frequently Asked Questions didn’t contain the answer to my issue
Environment check
- I’m using the latest
msw
version - I’m using Node.js version 14 or higher
Node.js version
v16.14.2
Reproduction repository
see inline
Reproduction steps
- I’m following https://github.com/mswjs/msw#node
index.mjs
import { setupServer } from "msw/node";
node index.mjs
node:internal/process/esm_loader:94
internalBinding('errors').triggerUncaughtException(
^
Error [ERR_UNSUPPORTED_DIR_IMPORT]: Directory import '/Users/timdaub/Projects/music-os-core/node_modules/msw/node' is not supported resolving ES modules imported from /Users/timdaub/Projects/music-os-core/index.mjs
Did you mean to import msw/node/lib/index.js?
at new NodeError (node:internal/errors:371:5)
at finalizeResolution (node:internal/modules/esm/resolve:414:17)
at moduleResolve (node:internal/modules/esm/resolve:983:10)
at defaultResolve (node:internal/modules/esm/resolve:1080:11)
at ESMLoader.resolve (node:internal/modules/esm/loader:530:30)
at ESMLoader.getModuleJob (node:internal/modules/esm/loader:251:18)
at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:79:40)
at link (node:internal/modules/esm/module_job:78:36) {
code: 'ERR_UNSUPPORTED_DIR_IMPORT',
url: 'file:///Users/timdaub/Projects/music-os-core/node_modules/msw/node'
Current behavior
- msw crashes with notes about ES modules.
Expected behavior
- msw doesn’t crash and respects nodejs requirements about directory imports
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:10 (5 by maintainers)
Top Results From Across the Web
'Directory import is not supported resolving ES modules' with ...
With ES6 modules you can not (yet?) import directories. Your import should look like this: import database from "./database/index.js".
Read more >Node.js – 'Directory import is not supported resolving ES ...
I'm using Node.js v14.13.0. app.js file: import database from './database'; database();. database/index.js file: import mongoose from 'mongoose'; ...
Read more >Error [ERR_UNSUPPORTED_DIR_IMPORT] in Node.js
The "Error [ERR_UNSUPPORTED_DIR_IMPORT]: Directory import is not supported" occurs in Node.js, when we try to use a directory import. To solve the error, ......
Read more >Directory import is not supported resolving ES modules when ...
Coding example for the question Directory import is not supported resolving ES modules when trying import { map } from 'rxjs/operators';-rx.js.
Read more >ES Modules in Node.js - Maxim Orlov
In ESM you can do await import('./a-module.mjs') without blocking the event loop. Node.js will put the import in the event loop and continue...
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
Thanks for wasting my time.
Closing this. See the explanation in https://github.com/mswjs/msw/pull/1202.