feature: Requesting support for node16/nodenext module resolution
Description
When using this library in a project that has the TSConfig setting moduleResolution set to node16 the TS compiler throws errors on every import and export ... from call.
Example:
../../node_modules/class-validator/types/index.d.ts(1,33): error TS2834: Relative import paths need explicit file extensions in EcmaScript imports when '--moduleResolution' is 'node16' or 'nodenext'. Consider adding an extension to the import path.
Proposed solution
- Change the
tsconfig.json#/compilerOptions/moduleResolutionsetting tonode16. - Bulk alter the codebase to correct the
importandexportpaths to have the full path to the target file with the extension. - Manually fix the outliers in the code: converting implicit
index.jsinto explicit being one such.
This should have no deleterious effect since, as far as I am aware, no version of TS or Node cared about having the filename and extension until ES6 came along.
I just ran across this issue myself but doesn't seem like it is a problem with class-validator. This is the issue I see:
` node_modules/class-validator/types/decorator/string/IsPhoneNumber.d.ts:2:29 - error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("libphonenumber-js")' call instead.
2 import { CountryCode } from 'libphonenumber-js'; ~~~~~~~~~~~~~~~~~~~
node_modules/libphonenumber-js/index.d.ts:18:8 - error TS2834: Relative import paths need explicit file extensions in EcmaScript imports when '--moduleResolution' is 'node16' or 'nodenext'. Consider adding an extension to the import path.
18 } from './types'; ~~~~~~~~~`
The libphonenumber-js problem is a separate issue. Fundamentally that problem is due to libphonenumber-js not handling its ESM exports correctly, which is causing problems both in this project and downstream projects.
Any suggestions on how to fix it?
The current file is a CommonJS module whose imports will produce 'require' calls;
however, the referenced file is an ECMAScript module and cannot be imported with 'require'.
Consider writing a dynamic 'import("libphonenumber-js")' call instead.
Please converse about the libphonenumber-js problem in https://github.com/typestack/class-validator/issues/1947, thank you. :)