diff --git a/packages/js/src/generators/library/library.ts b/packages/js/src/generators/library/library.ts index b93bb7e4dc819..00ecf12eaf330 100644 --- a/packages/js/src/generators/library/library.ts +++ b/packages/js/src/generators/library/library.ts @@ -523,6 +523,10 @@ function createFiles(tree: Tree, options: NormalizedLibraryGeneratorOptions) { tsConfig.options.moduleResolution === ts.ModuleResolutionKind.Node16 || tsConfig.options.moduleResolution === ts.ModuleResolutionKind.NodeNext ) { + // Node16 and NodeNext require explicit file extensions for relative + // import paths. Since we generate the file with the `.ts` extension, + // we import it from the same file with the `.js` extension. + // https://www.typescriptlang.org/docs/handbook/modules/reference.html#file-extension-substitution fileNameImport = `${options.fileName}.js`; } }