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.

support `.js` extension for imports in `.ts` files

See original GitHub issue

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

import bar from './bar.js'  // bar.js does not exist on disk, it is the transpilation result of bar.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

devDependencies:
+ loadr 0.1.1
+ tsm 2.0.0
+ uvu 0.5.1
dominikg@mb14:~/develop/uvu/examples/typescript.module$ pnpm test

> @ test /home/dominikg/develop/uvu/examples/typescript.module
> tsm node_modules/uvu/bin.js tests

(node:8503) ExperimentalWarning: --experimental-loader is an experimental feature. This feature could change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
Error: ENOENT: no such file or directory, open '/home/dominikg/develop/uvu/examples/typescript.module/src/math.js'

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
lukeedcommented, Oct 5, 2021

Resolved 😃 Thanks for opening this up

0reactions
karlhorkycommented, Nov 28, 2022

Nice, tsm@2.3.0 (PR #43) is working, thanks! 🙌

Read more comments on GitHub >

github_iconTop Results From Across the Web

Appending .js extension on relative import statements during ...
The Typescript compiler allows import statement without an extension. It then goes on to add ".js" extension to the corresponding output ...
Read more >
Provide a way to add the '.js' file extension to the end ... - GitHub
In order to use es6 modules in the browser, you need a .js file extension. However output doesn't add it. In ts: import...
Read more >
autoimport in typescript when use ES Module doesn't add .js ...
1.Create a TypeScript project with "module": "ESNext" in tsconfig.json and "type": "module" in package.json · 2.create testexport.ts file export a value. export ...
Read more >
Documentation - Module Resolution - TypeScript
Module resolution is the process the compiler uses to figure out what an import refers to. Consider an import statement like import {...
Read more >
tsc-esm-fix - npm
Moreover, if understand TS/49271 correctly, nodenext + pkg.json type: module requires the .js extension in .d.ts files of external ESM ...
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