hyperjump-io / uri

A small and fast library for validating, parsing, and resolving URIs (RFC 3986) and IRIs (RFC 3987).
MIT License
2 stars 1 forks source link

Usage problem with Mocha Test Explorer in VSCode #3

Closed ewrayjohnson closed 8 months ago

ewrayjohnson commented 8 months ago

When I try to use this package with Mocha Test Explorer in VSCode I get this error:

TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for ...\.test.ts
    at new NodeError (node:internal/errors:405:5)
    at Object.getFileProtocolModuleFormat [as file:] (node:internal/modules/esm/get_format:79:11)
    at defaultGetFormat (node:internal/modules/esm/get_format:124:36)
    at defaultLoad (node:internal/modules/esm/load:89:20)
    at nextLoad (node:internal/modules/esm/loader:163:28)
    at ESMLoader.load (node:internal/modules/esm/loader:603:26)
    at ESMLoader.moduleProvider (node:internal/modules/esm/loader:457:22)
    at new ModuleJob (node:internal/modules/esm/module_job:64:26)
    at ESMLoader.#createModuleJob (node:internal/modules/esm/loader:480:17)
    at ESMLoader.getModuleJob (node:internal/modules/esm/loader:434:34) {
  code: 'ERR_UNKNOWN_FILE_EXTENSION'
}
jdesrosiers commented 8 months ago

That error doesn't seem to have anything to do with this package. It's complaining about a file named .test.ts, which I assume is in your project. I'm happy to help debug, but I'd need more information.

jdesrosiers commented 8 months ago

I poked around a bit and I think I have a solution for you. The extension needs to be configured to support ESM packages (package.json that uses "type": "module"). This setting fixed the problem for me,

"mochaExplorer.nodeArgv": ["--loader", "ts-node/esm"]
ewrayjohnson commented 8 months ago

This does remove the specific error, but just causes another error for me:

test/app.test.ts(2,5): error TS7022: '__importDefault' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.
test/app.test.ts(2,67): error TS7006: Parameter 'mod' implicitly has an 'any' type.
test/app.test.ts(32,21): error TS2339: Property 'response' does not exist on type 'unknown'.

Thanks for your help.

jdesrosiers commented 8 months ago

Looks like it's trying to compile already complied typespcript. See, https://github.com/TypeStrong/ts-node/issues/883. My first guess would be to remove the "mochaExplorer.require": "ts-node/register" setting if you have it, but in my testing, it worked the same with or without that setting. Here's my full mochaExplorer settings. If you have anything other than those two things, try removing them.

"mochaExplorer.files": "test/**/*.ts",
"mochaExplorer.nodeArgv": ["--loader", "ts-node/esm"]

Here's the tsconfig.json I used in case that helps.

{
  "compilerOptions": {
    "module": "Node16",
    "target": "es2015",
    "moduleResolution": "Node16",
    "esModuleInterop": true,
    "strict": true,
    "allowJs": true
  }
}