0

everyone. I've been stuck on a minor issue for a few days, but I haven't been able to find the answer, so I'm reaching out for your help.

I am developing a personal project using Turborepo. The project consists of a root app and various packages, each structured according to their specific purposes.

Before I explain the issue, let me briefly describe the project structure.

📦apps
 ┣ 📂root - vike app
📦packages
 ┣ 📂api - generated API codes
 ┣ 📂store - zustand storage codes
 ┣ 📂root-ui-pack - UI pack for root app
 ┣ 📂constant - just constants
 ┣ 📂util - util codes
 ┣ 📂typescript-config - tsconfig configure package
 ┣ ...etc

Each of my project's submodules has its own package.json and tsconfig.json files. Specifically, the tsconfig.json files are structured to extend from a base typescript-config package. In other words, the root of every tsconfig.json in the packages is derived from the typescript-config package.

Let’s move on to an example package. The package.json and tsconfig.json for the constant package are as follows

package.json

{
    "description": "constant for node environment",
    "devDependencies": {
        "@repo/typescript-config": "workspace:*"
    },
    "exports": {
        "./*": "./src/*/index.ts"
    },
    "keywords": [],
    "license": "ISC",
    "name": "@repo/constant",
    "type": "module",
    "version": "1.0.0"
}

tsconfig.base.json (in typescript-config)

{
    "$schema": "https://json.schemastore.org/tsconfig",
    "compilerOptions": {
        "declaration": false,
        "declarationMap": false,
        "esModuleInterop": true,
        "incremental": false,
        "isolatedModules": true,
        "lib": ["es2022", "DOM", "DOM.Iterable"],
        "module": "es2022",
        "moduleDetection": "auto",
        "moduleResolution": "bundler",
        "noEmit": true,
        "noUncheckedIndexedAccess": true,
        "resolveJsonModule": true,
        "resolvePackageJsonImports": true,
        "skipLibCheck": true,
        "strict": true,
        "target": "es2022"
    }
}

tsconfig.json (in constant package)

{
    "extends": "@repo/typescript-config/base.json",
    "references": [
        {
            "path": "./tsconfig.lib.json"
        }
    ]
}

tsconfig.lib.json (in constant package)

Normally, spec and storybook would be managed with separate tsconfig files, but since this package is simply for managing constants, there are no references other than the tsconfig that handles the source code.

{
    "extends": "./tsconfig.json",
    "include": ["./src/**/*.ts"]
}

This constant package is set up so that it can be referenced in other packages using the @repo/constant format. For example, if the root-ui-pack package needs to reference it, the dependency is defined in root-ui-pack's package.json as "@repo/constant": "workspace:*".

This setup creates a symlink in root-ui-pack's node_modules pointing to the constant package.

With this setup, I expect that root-ui-pack would manage @repo/constant just like external dependencies such as zustand or react (since it's linked in node_modules).

I assumed that after this, VSCode's IntelliSense would work as expected based on the exports defined in the installed package. However, this was not the case.

Of course, if I manually type the import like import { var1 } from '@repo/constant/file1', it gets recognized correctly. But the automatic completion in VSCode doesn't work as intended.

Actually, I did find a workaround. If I add ./node_modules/@repo to the include array of each tsconfig.json, it does work.

However, I feel there must be a better, cleaner way to handle this.

I don't want to use alias, as I feel it doesn't align with the way I'm managing JIT packages. If I were to use an alias, I could just manage it based on folders instead of packages, so it's not really the approach I'm looking for.

I’ve spent several days searching for different solutions and pondering over this, even consulting multiple people—and even some non-human sources! But I haven’t been able to find a solid answer.

Can you help me solve this issue?

New contributor
Kapoo is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.