Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

esbuild@0.15.5 uses compilerOptions.baseUrl when resolving transitive dependencies #2481

Closed
merceyz opened this issue Aug 17, 2022 · 3 comments
Labels

Comments

@merceyz
Copy link

merceyz commented Aug 17, 2022

Describe the bug

When resolving transitive dependencies esbuild@0.15.5 tries to resolve them from compilerOptions.baseUrl which doesn't match what tsc does.

Resolving import "react" in directory "/tmp/tmp.1Iu4gSxpc7/node_modules/react-dom/cjs" of type "require-call"

  Read 13 entries for directory "/tmp/tmp.1Iu4gSxpc7/node_modules/react-dom/cjs"
  Checking for "react" in the "browser" map in "/tmp/tmp.1Iu4gSxpc7/node_modules/react-dom/package.json"
    Checking for "react"
    Checking for "react.tsx"
    Checking for "react.ts"
    Checking for "react.jsx"
    Checking for "react.js"
    Checking for "react.css"
    Checking for "react.json"
    Checking for "react/index"
    Checking for "react/index.tsx"
    Checking for "react/index.ts"
    Checking for "react/index.jsx"
    Checking for "react/index.js"
    Checking for "react/index.css"
    Checking for "react/index.json"
  Checking for "./cjs/react" in the "browser" map in "/tmp/tmp.1Iu4gSxpc7/node_modules/react-dom/package.json"
    Checking for "./cjs/react"
    Checking for "./cjs/react/index"
  Failed to find "react"
  Searching for "react" in "node_modules" directories starting from "/tmp/tmp.1Iu4gSxpc7/node_modules/react-dom/cjs"
    Attempting to load "/tmp/tmp.1Iu4gSxpc7/react" as a file
      Checking for file "react"
      Checking for file "react.tsx"
      Checking for file "react.ts"
      Checking for file "react.jsx"
      Checking for file "react.js"
      Found file "react.js"
  Read 12 entries for directory "/tmp/tmp.1Iu4gSxpc7"
  This import is under the effect of "/tmp/tmp.1Iu4gSxpc7/tsconfig.json"
  Primary path is "/tmp/tmp.1Iu4gSxpc7/react.js" in namespace "file"

Ref yarnpkg/berry#4732
Ref #2473 (comment)

To Reproduce

docker run --rm -it node:16.16.0 bash
cd $(mktemp -d)
yarn init -2
yarn set version 3.2.2
yarn config set nodeLinker node-modules
yarn add esbuild@0.15.5 react@18.2.0 react-dom@18.2.0
printf '{"compilerOptions": {"baseUrl": "."}}' > tsconfig.json
printf "import 'react-dom'" > index.ts
printf "this should not match" > react.js
yarn esbuild --log-level="verbose" --bundle ./index.ts
@evanw
Copy link
Owner

evanw commented Aug 19, 2022

FWIW this is not specific to Yarn. This happens when npm is used instead of Yarn. It looks like this has been esbuild's behavior for quite a while.

@merceyz
Copy link
Author

merceyz commented Aug 20, 2022

Indeed, that's why the reproduction uses the node-modules linker (node_modules folder)

@evanw evanw added the tsconfig label Dec 4, 2022
@evanw
Copy link
Owner

evanw commented Mar 24, 2023

I'm still not totally sure what to do about this. One reason why TypeScript doesn't do this is that it doesn't check JavaScript files. Another reason is that (I think?) it doesn't type packages, which is basically the equivalent of esbuild's --packages=external setting, which would also work here. So I'm not sure if esbuild's behavior should be that path mappings in tsconfig files shouldn't apply to JavaScript files, or that they shouldn't apply to node_modules files, or something else.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants