question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Directory import is not supported resolving ES modules

See original GitHub issue

Prerequisites

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

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:closed
  • Created a year ago
  • Reactions:1
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

15reactions
TimDaubcommented, Jul 9, 2022

Thanks for wasting my time.

5reactions
kettanaitocommented, Jul 4, 2022

Closing this. See the explanation in https://github.com/mswjs/msw/pull/1202.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found