Skip to content
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

ERR_UNSUPPORTED_DIR_IMPORT #87

Closed
loynoir opened this issue Sep 6, 2021 · 2 comments
Closed

ERR_UNSUPPORTED_DIR_IMPORT #87

loynoir opened this issue Sep 6, 2021 · 2 comments
Milestone

Comments

@loynoir
Copy link

loynoir commented Sep 6, 2021

Reproduce

$ yarn add web-streams-polyfill
// test.mjs
import { ReadableStream as PonyReadableStream } from  'web-streams-polyfill/ponyfill'
console.log(PonyReadableStream)

Expect

No error

Actual

$ node test.mjs
internal/process/esm_loader.js:74
    internalBinding('errors').triggerUncaughtException(
                              ^

Error [ERR_UNSUPPORTED_DIR_IMPORT]: Directory import 'XXX' is not supported resolving ES modules imported from XXX/test.mjs
Did you mean to import web-streams-polyfill/dist/ponyfill.js
  code: 'ERR_UNSUPPORTED_DIR_IMPORT',
  url: 'file:///XXX/web-streams-polyfill/ponyfill'
}

Else

import { ReadableStream as PonyReadableStream } from  'web-streams-polyfill/dist/ponyfill.js'
console.log(PonyReadableStream)
$ node test.mjs 
[Function: ReadableStream]
@MattiasBuelens
Copy link
Owner

The polyfill does not yet fully support native ESM in Node. I'm currently working on this for v4.0 in #83, which should land soon(ish).

For now, you can work around this by importing the .mjs file directly (as suggested by the error message):

import { ReadableStream as PonyReadableStream } from  'web-streams-polyfill/dist/ponyfill.mjs'

@MattiasBuelens MattiasBuelens added this to the v4.0.0 milestone Sep 6, 2021
@MattiasBuelens
Copy link
Owner

MattiasBuelens commented May 24, 2022

This is implemented in #83. Give it a spin with the latest beta release: v4.0.0-beta.3. 😉

Note that the polyfill's exports have changed in 4.0, see MIGRATING for more information. Your example would now look like this:

// test.mjs
import { ReadableStream as PonyReadableStream } from 'web-streams-polyfill'
console.log(PonyReadableStream)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants