-
Notifications
You must be signed in to change notification settings - Fork 25
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
TypeError: Unknown file extension ".ts" - esmodules support #70
Comments
please test with new v9.0.0 |
Thank you for your post... but "ts-mocha": "9.0.0" results in the same error as above. |
@AuroraLantean need a little bit of help, if you could help me to create a simple repo with your setup (package.json and m1.ts + utils.ts files and npm test command) I would try to investigate that repo and fix that issue and also look for a way to add it to the regression testing for your use-case. I guess it's related to the ts-node version, not sure why you have installed it in your project but it's different from ts-mocha version possibly clashing. |
Hi @piotrwitek , thank you for your quick reply. Please take the following code: |
For another example, I was able to reproduce it with the following repo after installing/using |
Pretty sure this is due to Not sure how to mangle |
Try |
Hello, having the same issue here. Trying @cn-ia solution did not work for me |
If that can help, I found out that this issue seems to be triggered when I do use the package Test command :
TsConfig:
|
For me, this was the problem. Removing |
Hey! I have the same issue. I do not have |
@SmashingQuasar I believe the issue is because If you run
Showing that although your project uses a newer |
Hello Everyone, thanks for multiple useful contributions here in this issue, I'll try to look into this issue today and propose some solutions, also I will try to include a special test case scenario on a branch in the repo to help with debugging. Cheers! |
I have created a branch with a reproduction test case for experimentation here: https://github.com/piotrwitek/ts-mocha/tree/support-for-node-es-modules After some research, the issue was indeed introduced by ts-node dependency not handling More details on ts-node
I won't have time to work on it anytime soon, but will try to help and accept PRs for this. Cheers! |
Let me know if you need guidance on the best way to use our ESM loader. |
Same issue. |
Same issue |
same issue |
Just ran into the same issue myself. |
Hello everyone,I have the same problem and I think the problem was caused by tsconfig.json: // ❌ when module = esnext
{
"compilerOptions": {
"module": "esnext"
}
}
// ✅ change module to commonjs,then everything is ok
{
"compilerOptions": {
"module": "CommonJS"
}
} Hope this trick can help. |
I got the same issue with
attempt to run test
|
seems like a problem with Node itself, if someone can make a working example using mocha and ts-node I would be able to integrate it into the library |
Needs the |
@cspotcode thanks for jumping in and correcting my assumptions! Could you point me to some examples or solutions that are using mocha and ts-node with ESM successfully that I could try? |
Google found this: TypeStrong/ts-node#1268 |
create .mocharc.json and
|
In my case, on of my dependencies (nanoid) added |
Nanoid got me too |
same problem here, and I need to use type: module |
The tsconfig.json contents taken from piotrwitek/ts-mocha#70 (comment)
came across this today
|
I've tried a variety of solutions in this thread. These did not work:
So, I'm kind of at a loss. |
i switched to vitest, almost there |
Like others, I suffer from this same pain. I have tried all solutions to no avail. If anyone has any updated information, please share. Thanks. |
hoping this can help somebody: I was able to make it work creating a .mocharc.json file with this content: { "node-option": [ "loader=ts-node/esm" ] } |
I tried adding this but then get: Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/<path-to-project>/node_modules/ts-node/esm' imported from /<path-to-project>/
at new NodeError (node:internal/errors:405:5)
at finalizeResolution (node:internal/modules/esm/resolve:324:11)
at moduleResolve (node:internal/modules/esm/resolve:943:10)
at defaultResolve (node:internal/modules/esm/resolve:1129:11)
at nextResolve (node:internal/modules/esm/loader:163:28)
at ESMLoader.resolve (node:internal/modules/esm/loader:835:30)
at ESMLoader.getModuleJob (node:internal/modules/esm/loader:424:18)
at ESMLoader.import (node:internal/modules/esm/loader:524:22)
at initializeLoader (node:internal/process/esm_loader:75:58)
at loadESM (node:internal/process/esm_loader:90:11) {
code: 'ERR_MODULE_NOT_FOUND'
} node 18.17.0 |
Do you have dependency |
Ha! I hadn't checked, assuming it was installed as a dep of Actually, I got the steps here to work without Thank you though. |
@webJose So, since I commented on this, I've switched test runners to Vitest in every scenario. As far as I can tell, Jest / Mocha just don't work, or don't work consistently, and Vitest works with very little configuration. |
@matthew-dean this is an order of magnitude much better. It just works, no config needed, and the API is really nice, default typescript support, no crap @types to import. If you're lucky enough to have the ability to switch please consider Vitest! |
Original post in Anchor repo: [(https://github.com/coral-xyz/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:
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
The text was updated successfully, but these errors were encountered: