question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

v13 is not compatible with "moduleResolution": "node12" of Typescript 4.5

See original GitHub issue

Which @angular/* package(s) are the source of the bug?

compiler

Is this a regression?

No

Description

.js suffix is required for native ESM on Node 12+ for all relative or absolute import statements

https://github.com/angular/angular/blob/master/packages/compiler/index.ts#L14

Please provide a link to a minimal reproduction of the bug

https://github.com/microsoft/TypeScript/issues/46408#issuecomment-946167806

Please provide the exception or error you saw

src/index.ts:1:15 - error TS2305: Module '"@angular/compiler"' has no exported member 'ParsedTemplate'.

1 import type { ParsedTemplate } from '@angular/compiler'
                ~~~~~~~~~~~~~~

src/index.ts:1:37 - error TS1471: Module '@angular/compiler' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead.

1 import type { ParsedTemplate } from '@angular/compiler'
                                      ~~~~~~~~~~~~~~~~~~~

src/index.ts:2:30 - error TS7016: Could not find a declaration file for module 'synckit'. '/Users/JounQin/Workspaces/Local/test/node_modules/synckit/lib/index.cjs' implicitly has an 'any' type.
  Try `npm i --save-dev @types/synckit` if it exists or add a new declaration (.d.ts) file containing `declare module 'synckit';`

2 import { createSyncFn } from 'synckit'
                               ~~~~~~~~~

src/worker.ts:1:15 - error TS2305: Module '"@angular/compiler"' has no exported member 'ParsedTemplate'.

1 import type { ParsedTemplate } from '@angular/compiler'
                ~~~~~~~~~~~~~~

src/worker.ts:1:37 - error TS1471: Module '@angular/compiler' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead.

1 import type { ParsedTemplate } from '@angular/compiler'
                                      ~~~~~~~~~~~~~~~~~~~

src/worker.ts:2:29 - error TS7016: Could not find a declaration file for module 'synckit'. '/Users/JounQin/Workspaces/Local/test/node_modules/synckit/lib/index.cjs' implicitly has an 'any' type.
  Try `npm i --save-dev @types/synckit` if it exists or add a new declaration (.d.ts) file containing `declare module 'synckit';`

2 import { runAsWorker } from 'synckit'
                              ~~~~~~~~~

src/worker.ts:5:11 - error TS2339: Property 'parseTemplate' does not exist on type 'typeof import("/Users/JounQin/Workspaces/Local/test/node_modules/@angular/compiler/index")'.

5   const { parseTemplate } = await import('@angular/compiler')
            ~~~~~~~~~~~~~


Found 7 errors.

Please provide the environment you discovered this bug in

@angular/compiler            13.0.0-rc.0

Anything else?

No response

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:2
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
JoostKcommented, Oct 21, 2021

That’s only because the JS bundles in @angular/compiler have already been bundled! But the .d.ts files have not.

2reactions
JoostKcommented, Oct 21, 2021

Using TypeScript 4.5 is not yet supported and we haven’t verified how it works in any way yet, especially not in combination with its node12 module resolution mode. We are aware that the published ESM bundles are missing the file extension; we’re relying on bundlers to use these modules. We were not aware that the .d.ts files have the same restriction, although that sort of makes sense now that you reported it. Our current thinking is that we may end up flattening the .d.ts files to get rid of the imports entirely, while still supporting pre-node12 module resolution.

Interestingly, the TypeScript team is considering making node12 module resolution support experimental in TS4.5 per https://github.com/microsoft/TypeScript/issues/46452. That issue also mentions that (some) bundlers do not support imports with .js file extensions, which is what TS would require us to write.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Documentation - TypeScript 4.5
TypeScript 4.5 introduces a way to override a specific built-in lib in a manner similar to how @types/ support works. When deciding which...
Read more >
Announcing TypeScript 4.5 Beta - Microsoft Developer Blogs
Today we are excited to announce the beta release of TypeScript 4.5! To get started using the beta, you can get it through...
Read more >
Add file extension when '--moduleResolution' is 'node16' or ...
WEB-53042 TypeScript 4.5: ECMAScript Module Support in Node.js. 4. Extention should be added automatically if '--moduleResolution' is 'node12' or 'nodenext'
Read more >
angular 2 could not find a declaration file for module 'date-fns'.
I just tried the typescript@next and moduleResolution: 'node12' with @angular/compiler@v13 , but tsc -b failed to build:.
Read more >
Can we support node16 instead of node12 in module for ...
scannerwork/.sonartmp/eslint-bridge-bundle/package/node_modules/express/lib/router/route.js:137:13) ERROR: at Route ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found