-
-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
support .js
extension for imports in .ts
files
#1
Comments
Waiting on the next version of esbuild which might handle this automatically: evanw/esbuild#1505 (comment) Also, TS 4.5 is still in beta so this isn't officially doable yet |
Also, could you just drop the extension in this case? import * as math from '../src/math';
// resolves to math.ts cuz it exists That uvu example only includes the ".js" extension inside the import to match the reproduction it was closing. The other "typescript" example doesn't include extensions in the imports because TS has never needed it when importing another TS file. For example: https://github.com/lukeed/uvu/blob/master/examples/typescript/tests/math.ts#L3 |
My understanding of authoring typescript esm is that you should always use regarding typescript 4.5: I think that only adds support for mts/cts, 4.4 already works with |
I've always left off extensions, but I also always only use TS alongside a bundler of some kind, so it doesn't matter. Going extension-less & relying on But you're right, it should match. Playing with it now – fairly easy on the ESM side. Unblocking |
Resolved :) Thanks for opening this up |
I think these fully-specified ESM paths (with extensions) may not be fully working yet - eg. with other extensions such as $ ls
index.ts abc.tsx
$ cat index.ts
import abc from './abc.js';
$ yarn tsm index.ts
Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/Users/k/p/project/abc.js' imported from /Users/k/p/project/index.ts
at new NodeError (node:internal/errors:371:5)
at finalizeResolution (node:internal/modules/esm/resolve:416:11)
at moduleResolve (node:internal/modules/esm/resolve:932:10)
at defaultResolve (node:internal/modules/esm/resolve:1044:11)
at resolve (file:///Users/k/p/project/node_modules/tsm/loader.mjs:1:870)
at Loader.resolve (node:internal/modules/esm/loader:89:40)
at Loader.getModuleJob (node:internal/modules/esm/loader:242:28)
at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:76:40)
at link (node:internal/modules/esm/module_job:75:36)
at processTicksAndRejections (node:internal/process/task_queues:96:5) {
code: 'ERR_MODULE_NOT_FOUND'
}
$ yarn tsc
✨ Done in 0.81s |
Should I open a new issue for that? |
Opened a PR instead: #33 |
Nice, |
It is supported in ts-node/esm and according to typescript that's the recommended way to import
https://twitter.com/orta/status/1444958295865937920
foo.ts
Right now this fails with ENOENT, here's how it looks like in uvu's typescript.module example when you use math.ts and utils.ts instead of .js
The text was updated successfully, but these errors were encountered: