Typescript / Mocha / V4 Issue
rzec-allma opened this issue · comments
I am using nanoid
v4 in a NextJS application and while the library works fine in the application itself, when I run any unit tests that include code that using nanoid
, I get this error:
TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for /Users/ryanzec/repositories/allma-web-app/mocha-setup.ts
My tsconfig.json
is:
{
"compilerOptions": {
"baseUrl": ".",
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true,
"types": ["cypress", "cypress-real-events"],
"paths": {
"$/*": ["./src/*"]
}
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
"exclude": ["node_modules", "**/*.spec.*"]
}
I know there is a similar issue related to v4 in node however that issue in that seems to be related specifically to importing not working and not the error I am getting. The unit tests work fine with v3 so I assume it is related to the ESM change though not sure why it is not working since I am using esnext
in my tsconfig.json
.
While I can and will use v3, just wanted to point this out to see if there is something I am doing wrong or something that needs to be fixed with the library itself.
Sorry, I have no idea and the environment stack here is too big for debug.
Did you change any config during the update?
Nope, the only difference between working and not working is v3.3.4 (working) and v4.0.0 (not working) of nanoid
.
Sorry, still have no idea.
Let’s keep it open, maybe somebody will know the answer.
Don’t worry to use v3, it is officially supported.
Same issue here. Upgrading to 4.0.0 causes ts-mocha (which uses ts-node) to throw Error: unknown file extension .ts
It could be related to the commit where "type": "module"
was added to package.json (4f55442), as some commenters posted in this thread TypeStrong/ts-node#1062.
Downgrading to 3.3.4 removes the errors, and my tests run again.
I have this exact issue.
Downgrading the nanoid from v4 to v3.3.4 solved it.