I am helping out on a testing project using WebdriverIO. We are having immense difficulty with TS serrtings, as the TS transpiler seems to correctly resolve TS modules, but the resolution fails during runtime.
For example, if I have a module:
// config/config.ts
export const config = {};
And then a file:
// someTest.ts
import { config } from './config/config`;
Then TS will correctly display the types for config
. However, when running the suite, I would get the message:
[0-2] 2023-04-18T09:07:54.651Z ERROR @wdio/runner: Error: Cannot find module '/Users/ronnyefronny/projects/wdio-demo/config/config' imported from /Users/ronnyefronny/projects/wdio-demo/test/step-definitions/VoiceflowStepDefs.ts
My tsconfig.json
is:
{
"compilerOptions": {
"moduleResolution": "node",
"declaration": true,
"module": "ESNext",
"baseUrl": "./",
"types": [
"node",
"@wdio/globals/types",
"expect-webdriverio",
"@wdio/cucumber-framework",
],
"target": "ESNext",
"esModuleInterop": true,
"resolveJsonModule": true,
}
}
And the rest of WDIO config is as recommended by their docs, and still nothing.
The thing that gets me, is that in their own example boilerplate repo, WDIO import TS modules as JS, and this confuses me to no end. I've been working with TS for a few years on both back- and front-end projects and have never needed to import TS modules as their transpiled JS counterparts.
That is, instead of
import { config } from './config/config';
The would do
import { config } from './config/config.js';
I would love to understand why this is happening, and more specifically, why I can't use regular TS imports in this case. What is the difference?