cf-content-types-generator
cf-content-types-generator copied to clipboard
Generated TypeScript Models Lack File Extensions in Import Statements When Using Node 16 Module Resolution
Hello,
first, thanks for this library and the efforts to maintain it!
I've encountered an issue using it in a TypeScript project with Node 16 and moduleResolution set to node16 (or nodenext) in the tsconfig.json.
When the TypeScript models are generated, the import statements in the generated files lack the .js extension for relative file paths. This is problematic because Node 16 requires explicit file extensions in ES module imports: https://nodejs.org/api/esm.html#mandatory-file-extensions
Example Error:
models/contentful-schemes/TypeDiscoverLandingPage.ts:3:48 - error TS2835: Relative import paths need explicit file extensions in EcmaScript imports when '--moduleResolution' is 'node16' or 'nodenext'. Did you mean './TypeBrandCarousel.js'?
Incorrect Import Statement:
export { isTypeArticleCarousel } from "./TypeArticleCarousel";
Expected Import Statement:
export { isTypeArticleCarousel } from "./TypeArticleCarousel.js";
tsconfig.json Configuration:
{
"module": "Node16",
"moduleResolution": "node16"
}
Questions and Offer to Contribute:
- Might this be a configurational problem on my end? Unfortunately, I am not able to change
moduleormoduleResolutionin my project, but maybe I missed a flag in the library to configure the module compatibility? - Is this a known issue? If so, is there a planned fix?
- I'd like to contribute a fix for this issue. For that, could you guide me to the part of the codebase where the import statements are generated?
Thank you!
Still waiting for an answer here