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 when used in esm project #904

Closed
asokani opened this issue Nov 12, 2024 · 4 comments
Closed

ERR_UNSUPPORTED_DIR_IMPORT when used in esm project #904

asokani opened this issue Nov 12, 2024 · 4 comments

Comments

@asokani
Copy link

asokani commented Nov 12, 2024

I’m unable to run my ESM project with this library due to the following error:

Error [ERR_UNSUPPORTED_DIR_IMPORT]: Directory import '/app/node_modules/buffer/' is not supported resolving ES modules imported from /app/node_modules/nsfwjs/dist/esm/index.js

The issue is caused by this line in dist/esm/index.js

import { Buffer } from "buffer/";

It can be fixed like this:

import { Buffer } from "buffer";

It might be possible to address this here:

import { Buffer } from "buffer/";

@mazenchami
Copy link
Contributor

@asokani thank you for opening this issue.

This was resolved in #898 and released in v4.2.1.

I'll be closing out this issue now but please reopen it if I miss understood your comment.

@asokani
Copy link
Author

asokani commented Nov 13, 2024

Sorry, you are missing the point. The problem is, the added "slash" in the v4.2.1 broke the ESM version of the library.

See this example: https://github.com/asokani/nsfwjs-esm

$ node dist/index.js
node:internal/process/esm_loader:46
      internalBinding('errors').triggerUncaughtException(
                                ^

Error [ERR_UNSUPPORTED_DIR_IMPORT]: Directory import '/tmp/nsfw-esm/node_modules/buffer/' is not supported resolving ES modules imported from /tmp/ee/node_modules/nsfwjs/dist/esm/index.js
Did you mean to import buffer/index.js?
    at new NodeError (node:internal/errors:405:5)
    at finalizeResolution (node:internal/modules/esm/resolve:218:17)
    at moduleResolve (node:internal/modules/esm/resolve:838:10)
    at defaultResolve (node:internal/modules/esm/resolve:1036:11)
    at DefaultModuleLoader.resolve (node:internal/modules/esm/loader:251:12)
    at DefaultModuleLoader.getModuleJob (node:internal/modules/esm/loader:140:32)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:76:33)
    at link (node:internal/modules/esm/module_job:75:36) {
  code: 'ERR_UNSUPPORTED_DIR_IMPORT',
  url: 'file:///tmp/nsfw-esm/node_modules/buffer/'
}

Node.js v20.5.0

However, I cannot reopen this issue - there's just a "comment" button. Can you @mazenchami please recheck?

@ghnp5
Copy link

ghnp5 commented Nov 16, 2024

Having the same problem.

The line needs to import from buffer/index.js and not just buffer/.

Or just buffer as was before. Version 4.2.0 works for me, still.

@mazenchami

@haZya
Copy link
Contributor

haZya commented Nov 26, 2024

The issue related to the bun runtime seems to have been fixed (oven-sh/bun#8683). It should be safe to remove the trailing slash now if that's causing any issues for others. Also in my testing, I couldn't reproduce any issue related to this on bun. Maybe someone can provide an example to reproduce this on bun if it still exists without the trailing slash.

Also, since buffer is a peer dep of this library I think installing buffer directly on the project and importing it on the main entry file should fix any issues without needing a trailing slash. 🤔

Johannes-Andersen added a commit to Johannes-Andersen/nsfwjs that referenced this issue Nov 27, 2024
anatawa12 added a commit to anatawa12/misskey that referenced this issue Jan 10, 2025
4.2.1 is not usable because of infinitered/nsfwjs#904
mi-gh-maintainer bot pushed a commit to misskey-dev/misskey that referenced this issue Jan 14, 2025
* fix: punycode.js が使用されていない場所がある問題

* fix: use punycode/punycode.js on backend

* fix: use punycode/punycode.es6.js on backend

* fix: d.ts missing declare keyword

* chore: don't use punycode.js on backend

* update pnpm-lock.yaml

* chore: remove punycode.d.ts

* chore: use punycode.js instead of punycode npm package

* chore: bump psl to 1.15.0

* chore: bump nsfwjs to 4.2.0

4.2.1 is not usable because of infinitered/nsfwjs#904

* chore: prevent loading node-fetch from tensorflow

* chore: DOMWindow['document'] => Document

IDK why DOMWindow['document'] fails, but might be related to tsc internal complexity limit

* fix: disable --trace-deprecation

---------

Co-authored-by: syuilo <[email protected]>
Ruruke pushed a commit to Ruruke/misskey that referenced this issue Jan 14, 2025
* fix: punycode.js が使用されていない場所がある問題

* fix: use punycode/punycode.js on backend

* fix: use punycode/punycode.es6.js on backend

* fix: d.ts missing declare keyword

* chore: don't use punycode.js on backend

* update pnpm-lock.yaml

* chore: remove punycode.d.ts

* chore: use punycode.js instead of punycode npm package

* chore: bump psl to 1.15.0

* chore: bump nsfwjs to 4.2.0

4.2.1 is not usable because of infinitered/nsfwjs#904

* chore: prevent loading node-fetch from tensorflow

* chore: DOMWindow['document'] => Document

IDK why DOMWindow['document'] fails, but might be related to tsc internal complexity limit

* fix: disable --trace-deprecation

---------

Co-authored-by: syuilo <[email protected]>
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

4 participants