-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Support importing types from a .mts
file from within a CommonJS file.
#58195
Comments
|
@andrewbranch points out that the concerns in the linked issue are specific to resolution hitting different targets in upstream packages due to revisions in their package jsons, but this argument doesn't apply at all to local relative paths |
The currently intended behavior is that you’re supposed to silence this error by adding |
I'm confused; isn't the context of this issue nodejs/node#51977, such that when that's "final", we need to have a new module resolution mode which re-allows (Hm, maybe not, as the above was just a "side point" of sorts...) |
This solves the my main issue. I did search for this, but wasn't able to figure it out based upon #53656. I was also trying to use I completely missed typescriptlang.org Stable Support By the way, the "value" of "resolution-mode" doesn't seem to matter for local files. This works fine. import type { User } from './models.mts' with { "resolution-mode": "require" }; Which leads to the question of why
It is a "side point", I was using it as part of the argument that importing ESM files from a CJS file is necessary to support. Given that, it would also preclude the need for |
Yeah, if that lands without a flag, there will be a new module mode / |
We should at least update the error message to suggest the resolution mode assertion |
It looks like Node 22 includes |
Under an experimental flag. |
🔍 Search Terms
"commonjs", "import", "type", "module"
✅ Viability Checklist
⭐ Suggestion
Proposal: Allow importing pure types from
.mts
files from a CommonJS file.The current behavior generates an unnecessary / incorrect error since no
require
will be emitted.Current error:
Please note, future versions of Node will support requiring an ESM module if a there is not a top level
await
. See:📃 Motivating Example
src/code.cts
src/models.mts
💻 Use Cases
In mixed code bases (especially as they transition from CommonJS to ESM) it is often necessary export the types from a module that are used in CommonJS files.
All shared types must be declared in CommonJS files or inferred using
Awaited
.Declaring shared types in CommonJS files.
The text was updated successfully, but these errors were encountered: