oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
73.09k stars 2.67k forks source link

--tsconfig-override is ignored; always loads tsconfig from cwd #7079

Open mnpenner opened 10 months ago

mnpenner commented 10 months ago

What version of Bun is running?

1.0.11+f7f6233ea

What platform is your computer?

Linux 4.4.0-19041-Microsoft x86_64 x86_64

What steps can reproduce the bug?

My project is structured like this:

tsconfig.json 
package.json
server
├── server.tsx
└── tsconfig.json
client
├── script.ts
└── tsconfig.json

In server/tsconfig.json I have:

{
    "extends": "../tsconfig.json",
    "compilerOptions": {
        "lib": [
            "ESNext",
            "dom"
        ],
        "jsx": "react-jsx",
        "jsxImportSource": "@mpen/jsxhtml"
    },
    "include": [
        "../node_modules/@mpen/jsxhtml/jsx.d.ts",
        "./**/*",
    ]
}

In the root tsconfig.json I have:

{
    "compilerOptions": {
        "target": "ES2022",
        "module": "CommonJS",
        "moduleResolution": "node",
        "declaration": true,
        "esModuleInterop": true,
        "forceConsistentCasingInFileNames": true,
        "strict": true,
        "exactOptionalPropertyTypes": true,
        "skipLibCheck": true,
        "resolveJsonModule": true
    }
}

When I run bun run --tsconfig-override server/tsconfig.json --hot server/server.tsx I get an error:

error: Cannot find module "react/jsx-dev-runtime" from ".../myproject/server/server.tsx"

But as you will notice, I have jsxImportSource set in server/tsconfig.json but Bun isn't using it for some reason, even though I explicitly told it to use that tsconfig with --tsconfig-override.

If I add

        "jsx": "react-jsx",
        "jsxImportSource": "@mpen/jsxhtml"

to the root tsconfig, then it works fine. So for whatever reason, Bun seems to be not using the correct tsconfig, even when I explicitly try to set it.

What is the expected behavior?

Use the tsconfig specified with --tsconfig-override, or even better, automatically use the correct tsconfig (closest to the file I'm trying to run, not cwd)

What do you see instead?

Error.

Additional information

No response

hschletz commented 8 months ago

Same here (bun 1.0.18). The path is evaluated (nonexistent path will cause an error), but the file content is ignored and the root tsconfig.json is loaded. This can be verified by providing a syntactically invalid file which will not cause a message. Putting a syntax error in the root tsconfig.json will cause a warning in either case.

Issue title should be changed because the issue is not related to JSX.

liamdawson commented 1 month ago

I can confirm this is still an issue in bun v1.1.21 on MacOS 14.6:

bun run --tsconfig-override=tsconfig.server.json ./file.ts

doesn't respect the compilerOptions.paths defined in tsconfig.server.json, but they work if I put them in tsconfig.json instead.