-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
transpileModule
does not account for package.json type
when ran with node16/nodenext module setting
#53022
Comments
Hitting the same problem. Seems like the cause of it is the following:
Unfortunately the host cannot know about Might be this is expected behaviour. For instance, if the |
Here is a patch of the - fileExists: (fileName): boolean => fileName === inputFileName,
- readFile: () => "",
+ fileExists: (fileName) => fileName.endsWith("package.json") ? sys.fileExists(fileName) : fileName === inputFileName,
+ readFile: (fileName) => fileName.endsWith("package.json") ? sys.readFile(fileName) : "", |
I'll wait for @rbuckton to make a final call, but my impression is that the entire point of |
I concur with @RyanCavanaugh. |
transpileModule treats NodeNext as CommonJS because it doesn't read the package.json. Therefore we need to override it. Also see microsoft/TypeScript#53022 (the filename workaround doesn't work). Fixes #11086
transpileModule treats NodeNext as CommonJS because it doesn't read the package.json. Also see microsoft/TypeScript#53022 (the filename workaround doesn't work). Related to sveltejs/kit#11086
Bug Report
🔎 Search Terms
transpileModule node16 nodenext
🕗 Version & Regression Information
Checked with
@4.9.4
@beta
-5.0.0-beta
@next
-5.1.0-dev.20230227
It's only about
node16
/nodenext
and therefore doesn't affect TS versions before 4.7⏯ Playground Link
https://github.com/romkhub/ts-transpile-node16
The repo illustrates how
tsc
provides ESM, whiletranspileModule
gives CJS upon the same setup.After debugging I see it related to this code which, as I understand, essentially hides all the files except the one transpiled.
My real-world scenario is an attempt to use node16 TS setup in a repo built with webpack and ts-loader in
transpileOnly
mode. WithtranspileOnly: true
I get CJS,transpileOnly: false
- ESM🙁 Actual behavior
transpileModule
does not recognize"type": "module"
in package.json and emit CJS, whiletsc
emits ESM🙂 Expected behavior
JS emitted by
transpileModule
is the same as oftsc
The text was updated successfully, but these errors were encountered: