-
-
Notifications
You must be signed in to change notification settings - Fork 43
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
Bug: prefer-node-protocol rule and deprecated builtins #337
Comments
Thank you for the report! This should have been covered by https://github.com/eslint-community/eslint-plugin-n/blob/master/lib/rules/prefer-node-protocol.js#L154 |
@pascalduez One thing I forgot to mention is that if you're importing: const punycode = require('punycode'); Then you're going to be importing the wrong module! You need to import punycode like this: const punycode = require('punycode/'); |
* test: Add failing test for #337 * fix: Use our data set to work out if a module is a node module
Yes thank you, I was aware of this workaround, but it does not work with ES modules. And honestly, feels a bit hacky. But as you mentioned this issue made us realize that we are using different modules server side (the Node buitin) and client side (the npm package) which is worrying because they are supposed to have slight differences. At the end we are going to switch to Thanks for the very quick fix! |
I think it may be better to suggest I was unaware of that package as a mirror of the punycode repo! |
Environment
Node version: 22.7.0
npm version: 10.8.2
ESLint version: 8.57.0
eslint-plugin-n version: 17.10.2
Operating System: Linux
What rule do you want to report?
prefer-node-protocol
Link to Minimal Reproducible Example
https://eslint-online-playground.netlify.app/#eNptkMFugzAMhl8l8qUXoFuPVNtpb7H0gIJB2YITOaFqhXj3OQ1om9SLY1uf//z2ApHNEW/dFBw2XxFasFPwnFSY6W58j2pgP6nDXh7OUAFGZyk1xtNgx39TVHC9IXVw82ipJg1nTZrw9qB6HLrZJfWpSaklB6UKGVu1iMhalSbPDnOrVEp06RgYB+SaxEwd2CdvvNPQihggs2cN1e9AHrkiR+vFQivF+9vp1Lw2L0LtzHop2ZofCRexKkuGznx3Yz6KJ1nwIakh3QMWpcn34m7T0dDj9QMDUo9kLMbMbC72Y5Qx1yWMkm/fP7nUX2qztML6A41SiaQ=
What did you expect to happen?
The
prefer-node-protocol
is reporting the import ofpunycode
, as missing thenode:
prefix, which is intended. The issue is thepunycode
Node builtin is deprecated and we are encouraged to use a third party module instead.Which we do in our codebase currently. We use a module called
punycode
, so we don't want to prefix it obviously.See https://nodejs.org/api/punycode.html#punycode
So it would be a good thing to maybe have another option to the rule to be able to ignore certain Node builtins?
Alternatively the plugin could maintain a list of deprecated builtins related to the Node version and exclude them, but that sound quite tedious and not optimal. Also not working with ESM.
We should note that we can work around this issue with
import punycode from 'punycode/'
but is that's not realy satisfactory.Participation
Additional comments
No response
The text was updated successfully, but these errors were encountered: