TypeError: Unknown file extension ".ts" - esmodules support
See original GitHub issueOriginal post in Anchor repo: [(https://github.com/project-serum/anchor/issues/1286)]
Anchor.toml [script] command: test = “yarn run ts-mocha -p ./tsconfig.json -t 1000000 tests/**/*.ts”
The problem is the m1.ts file cannot import functions from another ts file!!!??? in my utils.ts
export const log1 = console.log;
in my m1.ts file:
import { log1 } from './utils';
describe('scenario1', async () => {
it('initialize', async () => {
log1('\n---------== init');
});
});
the imported log1 function or any other function will cause the Unknown file extension “.ts” error!!??
my local package dependencies: “mocha”: “^9.1.3”, “ts-mocha”: “^9.0.0-alpha1”, “ts-node”: “^10.4.0”, “typescript”: “^4.5.4”
Please advise. Thank you

Issue Analytics
- State:
- Created 2 years ago
- Reactions:9
- Comments:27 (6 by maintainers)
Top Results From Across the Web
Can't run my Node.js Typescript project TypeError ...
Can't run my Node.js Typescript project TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for /app/src/App.ts · Ask Question.
Read more >Error: unknown file extension .ts · Issue #1062 - GitHub
Expected Behavior Load typescript files Actual Behavior When I try to execute a typescript file I get the following error message: TypeError ......
Read more >ts node unknown file extension ".ts" - You.com | The Search ...
My setup: I run my code in Node 16.13.2; I build with Gulp. Build is successful and I can run my code with...
Read more >ts-node - npm
This error is thrown by node when a module has an unrecognized file extension, or no extension at all, and is being executed...
Read more >ES Modules in NodeJS - Troubleshooting Resources
Node runtime powered by esbuild, supports TS and ESM. See my tooling section in my TS ... Make sure all imports include file...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hello everyone,I have the same problem and I think the problem was caused by tsconfig.json:
Hope this trick can help.
Try
ts-mocha -n loader=ts-node/esm -p tsconfig.json tests/**/*.test.tsvia npm scripts, it works for me! (Optional) Checknpx ts-mocha --helpfor more details of this option.