You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If your tsconfig.json has "module": "ES2020" or later (e.g you are outputting ESM and not CJS), TypeScript doesn't rewrite import './foo' to import './foo.js' in the transpiled output - instead you have to use import './foo.js' in your .ts file.
This module then breaks because it (quite reasonably) detects './foo.js' as a dependency which of course doesn't exist.
I've hacked round it by replacing the file extension here and here but it doesn't take into account if ./foo.js does actually exist and that's what you meant to import. I don't know the AST well enough to make that change, but a simple fs.existsSync should be enough?
Another workaround is to run the dep checker over the transpiled output instead of the ts source, but then you lose any import type declarations, so it's not ideal.
If your
tsconfig.json
has"module": "ES2020"
or later (e.g you are outputting ESM and not CJS), TypeScript doesn't rewriteimport './foo'
toimport './foo.js'
in the transpiled output - instead you have to useimport './foo.js'
in your.ts
file.This module then breaks because it (quite reasonably) detects
'./foo.js'
as a dependency which of course doesn't exist.I've hacked round it by replacing the file extension here and here but it doesn't take into account if
./foo.js
does actually exist and that's what you meant to import. I don't know the AST well enough to make that change, but a simplefs.existsSync
should be enough?Another workaround is to run the dep checker over the transpiled output instead of the ts source, but then you lose any
import type
declarations, so it's not ideal.Refs: https://devblogs.microsoft.com/typescript/announcing-typescript-4-7/#type-in-package-json-and-new-extensions
The text was updated successfully, but these errors were encountered: