wallabyjs / quokka

Repository for Quokka.js questions and issues
https://quokkajs.com
1.18k stars 31 forks source link

tsconfig compilerOptions paths not working #949

Closed pietgk closed 6 months ago

pietgk commented 6 months ago

tsconfig compilerOptions paths not working

in Quokka in vscode on import from @dal/db in below code gives

​​​​​Quokka PRO 'repl.ts' (node: v18.17.1, TypeScript: v4.9.5 + swc)​​​​

​Install "@dal/db" package for the current quokka file​
​Install "@dal/db" package into the project​
 
Cannot find module '@dal/db' 
Require stack: 
- <rootDir>/services/mindlerapi/src/procedures/application/repl.js 
  ​​​​​at ​​​​​​​​Proxy.Module._resolveFilename.sharedData.moduleResolveFilenameHook.installedValue​​​ ​./node_modules/@cspotcode/source-map-support/source-map-support.js:811​
  ​​​​​at ​​​​​​​​Proxy.Module._resolveFilename​​​ ​./node_modules/tsconfig-paths/src/register.ts:90​
  ​​​​​at ​​​​​​services/mindlerapi/src/procedures/application/repl.ts:4:1​

Is this issue related to Quokka not outputting the expected results of your code?: Yes

in ts-node with cwd ~/dev/monorepo-3.0/services/mindlerapi it can import @dal/db

npx ts-node  -r tsconfig-paths/register ./src/procedures/application/repl.ts

Sample code

import { getOrCreateClient } from "@dal/db";

const repl = async () => {
  const dbClient = await getOrCreateClient();
  const countries = dbClient.selectFrom("Countries").execute();
};

repl().then();

I did add quokka.json in the root of the monorepo containing:

{
  "ts": {
    "compilerOptions": {
      "module": "commonjs"
    }
  },
  "env": {
    "params": {
      "runner": "-r tsconfig-paths/register"
    }
  }
}

services/mindlerapi/tsconfig.json:

{
  "extends": "../../config/typescript/tsconfig.base.json",
  "compilerOptions": {
    "allowUnreachableCode": false,
    "allowUnusedLabels": false,
    "noFallthroughCasesInSwitch": true,
    "noImplicitOverride": true,
    "noImplicitReturns": true,
    "noUncheckedIndexedAccess": true,
    "noUnusedParameters": true,
    "declaration": false,
    "target": "ES2021",
    "outDir": "./build",
    "baseUrl": "../../",
    "paths": {
      "@shared/*": ["shared/*"],
      "@dal/*": ["services/mindlerapi/src/dal/*"],
      "@core/*": ["services/mindlerapi/src/core/*"],
      "@test/*": ["services/mindlerapi/test/*"]
    },
    "module": "NodeNext"
  },
  "include": [
    "infra",
    "./src",
    "./test",
    "migrator",
    "vitest.config.mts",
    "./src/core/environment.d.ts"
  ],
  "exclude": ["examples"]
}

Sample repository link

See this example repo for a full reproduction of the issue.

Code editor version

Visual Studio Code v1.89.0

OS name and version

OSX

smcenlly commented 6 months ago

Based on the information you've provided, we're not exactly sure why it's not working for you, but the .quokka configuration certainly looks problematic.

Quokka has its own integration with tsconfig-paths and loading setting this using env.params.runner will definitely cause problems. You shouldn't have to do anything for Quokka to pick up your tsconfig-paths if your TypeScript configuration(s) are correctly configured.

The first thing I would try is to remove the env setting from your .quokka configuration but I expect you've already tried this and that's why you added it in the first place?

We have created a sample repo based on the configuration that you provided, and test.ts in the project root is working for us.

Could you please update the sample repo to break in the same way that you're seeing as your project?

pietgk commented 6 months ago

@smcenlly Thx for the starter repo. I created a forked version of the repo with a readme with a description of the reproduced issue and a working ts-node example.

you where also correct on the assumption regarding .quokka conf being added to try to solve the issue. the example repo is without any specific quokka config.

smcenlly commented 6 months ago

Thanks for providing the sample. This has been fixed in the latest version of Quokka for VS Code (v1.0.640).

pietgk commented 6 months ago

I can confirm that it now works.