dependents / dependents/detective-typescript
Support ESM typescript modules
- Dominant language
- JavaScript
- Stars
- 65
- Forks
- 29
- PR merge metrics
- No merged PRs in 30d
Description
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](https://github.com/dependents/detective-typescript/blob/main/index.js#L37) and [here](https://github.com/dependents/detective-typescript/blob/main/index.js#L45) 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.
Refs: https://devblogs.microsoft.com/typescript/announcing-typescript-4-7/#type-in-package-json-and-new-extensions
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.