-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Enhancement: [no-require-imports] Add option allowJson
#5314
Comments
Import assertions are stable and unflagged in Node. JSON modules are experimental but IMO there's little reason to not use it for non-library code. |
I gave it a try and it’s not supported in Node.js 14. It is supported in Node.js 18, but it prints a warning stating it’s experimental. This doesn’t look great for CLIs. |
Indeed, many reasons to stop using Node 14 😄 I do use it personally and I find the fact that the code is fully ESM more pleasing than that I get a warning. |
I can’t argue with that! However, Node.js 14 is still a supported LTS, and I believe this TypeScript syntax is a nice way to deal with JSON files for now. |
Given that node14 will EOL in april next year - is it worth adding an option to support the old way of doing things when people will be moving to the new way relatively soon? Looking into it - it's supported in node 16 behind a flag, but node16 will EOL a few months after node 14. It's fully supported in node18, which will EOL in 3 years. I'm not entirely convinced that an option is the best of ideas given the above and given how infrequent a usecase it is to directly import JSON. |
I can think of one legitimate reason to import |
Before You File a Proposal Please Confirm You Have Done The Following...
My proposal is suitable for this project
Link to the rule's documentation
https://typescript-eslint.io/rules/no-require-imports/
Description
If
module
intsconfig.json
is set toNode16
, TypeScript 4.7 will convertimport … = require('…')
statements to require calls created using_createRequire
.As long as import assertions are not allowed in Node.js, I believe this is a nice syntax to read
package.json
files.I propose to add an option named
allowJson
tono-require-imports
that allows require imports of JSON files.Fail
Pass
Additional Info
In:
Out:
TypeScript playground
The text was updated successfully, but these errors were encountered: