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

punycode/ is misflagged as requiring the node: prefix #1931

Closed
nbouvrette opened this issue Oct 10, 2022 · 5 comments
Closed

punycode/ is misflagged as requiring the node: prefix #1931

nbouvrette opened this issue Oct 10, 2022 · 5 comments

Comments

@nbouvrette
Copy link

import { encode as punycodeEncode } from 'punycode/'

Is reporting:

Prefer `node:punycode/` over `punycode/`.eslint[unicorn/prefer-node-protocol](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/v44.0.0/docs/rules/prefer-node-protocol.md)

When in fact, node:punycode is deprecated and punycode/ is a npm package.

@fisker
Copy link
Collaborator

fisker commented Oct 10, 2022

silverwind added a commit to silverwind/eslint-plugin-unicorn that referenced this issue Dec 15, 2022
The `punycode` core module is deprecated since Node 7.0.0, it should not
be used anymore. There is a same-name npm module which is the
recommended alternative, but it must be imported without prefix
obviously.

Fixes: sindresorhus#1931
silverwind added a commit to silverwind/eslint-plugin-unicorn that referenced this issue Dec 15, 2022
silverwind added a commit to silverwind/eslint-plugin-unicorn that referenced this issue Dec 15, 2022
silverwind added a commit to silverwind/eslint-plugin-unicorn that referenced this issue Dec 15, 2022
@silverwind
Copy link
Contributor

silverwind commented Dec 15, 2022

I think to fix this, the rule could just ignore the import if the specifier ends in /, which in itself seems to be some kind of hack specific to node's module loader (I would not recommend using that, as it's bound to cause issues in other loaders).

@silverwind
Copy link
Contributor

silverwind commented Dec 16, 2022

The hack with punycode/ does not work in node ESM, it only works in CJS, so I suggest to only support it for CJS, if at all. Better alternatives include either using punycode/punycode.js or the punycode.js npm module.

> await import("punycode/")
Uncaught:
Error [ERR_UNSUPPORTED_DIR_IMPORT]

I also opened mathiasbynens/punycode.js#122 for the punycode authors to update their suggestions.

@kachkaev
Copy link
Contributor

kachkaev commented Dec 20, 2022

Same here with import { Buffer } from "buffer/" being converted to import { Buffer } from "node:buffer/".

I tried import { Buffer } from "buffer/index.js" but it got converted to import { Buffer } from "node:buffer/index.js" too.

@fisker
Copy link
Collaborator

fisker commented Apr 7, 2023

Fixed by #2060

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

No branches or pull requests

5 participants