-
-
Notifications
You must be signed in to change notification settings - Fork 535
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
Directory import is not supported resolving ES modules #1201
Comments
Hey, @TimDaub. Thanks for reporting this. I believe the issue is not in the example but in the configuration. Perhaps we need to configure something additionally to let |
Here's how I think this should be fixed:
|
I'm tentative to merge anything until this is properly looked into. There is no technical issue at hand: having to require What interests me:
|
As a nodejs developer being aware of unsupported directory imports, it requires contextual knowledge that msw wants me to use them anyways in ES modules. |
I'd like to add my two cents to the discussion as well. I've been struggling with using both
They shared with me a repository that explains how that resolution algorithm works, and how to fix it. Maybe it could be useful to move forwards on this as well? |
Thanks for the input, @antoinerey! That's the way ESM adoption progresses: it's hard and has no backward compatibility. ESM works well only with other ESM. It's like an MSW is not an ESM in terms of
I think this may be resolved by introducing explicit module mapping, like |
Closing this. See the explanation in #1202. |
Thanks for wasting my time. |
We are running msw in a NextJS project using TypeScript and experience a similar error. Any feedback/help would be greatly appreciated, since it is directly linked to the msw lib. Package Versions: {
"dependencies": {
"next": "12.1.6"
"msw": "^0.47.3"
"typescript": "4.6.4"
}
}
Error in Terminalerror - Error [ERR_UNSUPPORTED_DIR_IMPORT]: Directory import '/Users/.../Projects/Arribatec/frontdesk-admin/node_modules/@mswjs/interceptors/lib/interceptors/C
lientRequest' is not supported resolving ES modules imported from /Users/.../Projects/Arribatec/frontdesk-admin/node_modules/msw/lib/node/index.mjs
Did you mean to import @mswjs/interceptors/lib/interceptors/ClientRequest/index.js?
Error [ERR_UNSUPPORTED_DIR_IMPORT]: Directory import '/Users/.../Projects/Arribatec/frontdesk-admin/node_modules/@mswjs/interceptors/lib/interceptors/ClientReq
uest' is not supported resolving ES modules imported from /Users/.../Projects/Arribatec/frontdesk-admin/node_modules/msw/lib/node/index.mjs
Did you mean to import @mswjs/interceptors/lib/interceptors/ClientRequest/index.js?
at new NodeError (node:internal/errors:387:5)
at finalizeResolution (node:internal/modules/esm/resolve:425:17)
at moduleResolve (node:internal/modules/esm/resolve:1006:10)
at defaultResolve (node:internal/modules/esm/resolve:1214:11)
at nextResolve (node:internal/modules/esm/loader:165:28)
at ESMLoader.resolve (node:internal/modules/esm/loader:844:30)
at ESMLoader.getModuleJob (node:internal/modules/esm/loader:431:18)
at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:76:40)
at link (node:internal/modules/esm/module_job:75:36) {
code: 'ERR_UNSUPPORTED_DIR_IMPORT',
url: 'file:///Users/.../Projects/Arribatec/frontdesk-admin/node_modules/@mswjs/interceptors/lib/interceptors/ClientRequest',
page: '/'
Import in _app.tsx// file: ./pages/_app.tsx
import { setupWorker } from "msw";
import { setupServer } from "msw/node";
if (process.env.MOCK_API && /TRUE|true/.test(process.env.MOCK_API)) {
typeof window === "undefined"
? setupServer(...handlers).listen()
: setupWorker(...handlers).start();
}
.... |
Please read thisThere is no support for ESM right now. MSW simply doesn't ship as ESM so you cannot use it in your ESM setup. There's no need to report it as an issue because it's a known missing feature. Great but what should I do?
Don't expect things to magically happen. We all have lives and we all have jobs. If you need ESM support for work, then dedicate your working time to make it happen. If you need ESM support for hobby projects, then dedicate your spare time to make it happen. If you expect the same from me, than I see no reason not to expect the same from you. With that being said, I'm locking this conversation. |
Prerequisites
Environment check
msw
versionNode.js version
v16.14.2
Reproduction repository
see inline
Reproduction steps
index.mjs
Current behavior
Expected behavior
The text was updated successfully, but these errors were encountered: