oven-sh / bun

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

Path re-mapping does not work in test context #3617

Open ceopaludetto opened 1 year ago

ceopaludetto commented 1 year ago

What version of Bun is running?

0.6.14

What platform is your computer?

Darwin 22.5.0 arm64 arm

What steps can reproduce the bug?

Configure tsconfig.json:

{
  "compilerOptions": {
    "baseUrl": ".",
    "paths": {
      "~/*": ["./src/*"]
    }
  }
}

Create a test folder in root:

src/number.ts
test/number.test.ts
tsconfig.json

Create a simple test:

// number.test.ts
import { displayMax } from "~/number"

...

What is the expected behavior?

The import of ~/number should work as expected

What do you see instead?

-> bun --cwd packages/utilities test $ bun test bun test v0.6.14 (\b5665739)

test/number.test.ts:

error: Could not resolve: "~/number". Maybe you need to "bun install"?

import { displayMax } from "~/number"; ^

-> bun test
bun test v0.6.14 (\b5665739)

test/number.test.ts:

error: Could not resolve: "~/number". Maybe you need to "bun install"?

import { displayMax } from "~/number"; ^

Screenshot:

Screenshot 2023-07-12 at 10 39 10

Additional information

I'm running bun in a pnpm monorepo

Jarred-Sumner commented 1 year ago

Having trouble reproducing this. Would you be willing to upload a zip file or link to a git repo to clone that reproduces this issue?

image
ceopaludetto commented 1 year ago

After some investigation I found the problem. When you extend tsconfig with a custom package, path aliases stop working on bun test(and probably on every bun execution context like bun run).

Minimal reproduction: https://codesandbox.io/p/sandbox/bun-reproduction-v3gw9h

As you can see, in ./packages/example/tsconfig.json we have:

{
  "extends": "@acme/configuration/tsconfig.base.json",
  "compilerOptions": { ... }
}

If you comment the extends line, path aliases will start to work again. Actually there's another strange behavior, if you extends from a local file, something like "extends": "./tsconfig.base.json" it also work as expected. Only inheritances from other packages causes the bug

nicoabie commented 1 year ago

@Jarred-Sumner congrats on the release of 1.0

Will the team be able to allocate some time to look into this? @ceopaludetto was able to put a minimal reproduction example.

Can we be of help in any way?

Thanks in advance

ceopaludetto commented 1 year ago

Seems to be fixed on Bun 1.0.2

nicoabie commented 1 year ago

@ceopaludetto feel free to close this if you can confirm it is working as expected now

olosegres commented 8 months ago

It is still reproducible, using bun test v1.0.22

It works only without "extends": "./some.config.json" (extending config from local file)

kcstechnis commented 6 months ago

It's still the case, when I extend the tsconfig in a monorepo.

Version: 1.0.30

dominictobias commented 1 month ago

Doesn't work with references either:

{
  "files": [],
  "references": [
    {
      "path": "./tsconfig.app.json"
    },
    {
      "path": "./tsconfig.node.json"
    }
  ]
}

Some of the vite official templates do that. I can just change to one tsconfig.json but just FYI

Leka74 commented 1 month ago

Still an issue with v1.1.22.

jasongitmail commented 3 weeks ago

It works without "extends": "./some.config.json"

I found this to stil be an issue and this was the cause in mine too; i.e. aliases defined in tsconfig.jsonc fail when "extends": "./.svelte-kit/tsconfig.json" exists in my tsconfig.jsonc, but they work (allowing my bun:test tests to pass) if I remove the extends property.

Bun 1.1.26

jasongitmail commented 3 weeks ago

@Electroid this is worth reopening please