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

pnp: esbuild@0.15.2 unable to resolve dependencies of virtual dependencies outside of the project directory #2463

Closed
merceyz opened this issue Aug 12, 2022 · 6 comments

Comments

@merceyz
Copy link

merceyz commented Aug 12, 2022

Describe the bug

In a Yarn PnP project with the cache located outside of the project directory esbuild@0.15.2 is unable to resolve the dependencies of virtual dependencies.

Verbose log
⬥ [VERBOSE] Resolving import "./foo.js" in directory "/tmp/tmp.mfHdqKXG1S" of type "entry-point"

  Read 20 entries for directory "/"
  Read 3 entries for directory "/tmp"
  The file "/tmp/tmp.mfHdqKXG1S/package.json" exists
  The file "/tmp/tmp.mfHdqKXG1S/.pnp.cjs" exists
    Extracted JSON data from "/tmp/tmp.mfHdqKXG1S/.pnp.cjs"
  Read 10 entries for directory "/tmp/tmp.mfHdqKXG1S"
  Read 10 entries for directory "/tmp/tmp.mfHdqKXG1S"
  No "browser" map found in directory "/tmp/tmp.mfHdqKXG1S"
  Attempting to load "/tmp/tmp.mfHdqKXG1S/foo.js" as a file
    Checking for file "foo.js"
    Found file "foo.js"
  Read 10 entries for directory "/tmp/tmp.mfHdqKXG1S"
  Primary path is "/tmp/tmp.mfHdqKXG1S/foo.js" in namespace "file"

⬥ [VERBOSE] Resolving import "react-dom" in directory "/tmp/tmp.mfHdqKXG1S" of type "require-call"

  Read 10 entries for directory "/tmp/tmp.mfHdqKXG1S"
  Using Yarn PnP manifest from "/tmp/tmp.mfHdqKXG1S/.pnp.cjs" to resolve "react-dom"
    Found parent locator: ["tmp.mfHdqKXG1S", "workspace:."]
    Found parent package at "./"
    Found dependency locator: ["react-dom", "virtual:eab6b77f32a25cfb9c846be2326d2170fc3b644e0bb968ffea80b49bbcf2348fd5b488425ad5f2a114b5ae4ed4c7cb4a6f8bbb1ad8c499f9796bf9a360e58b5e#npm:18.2.0"]
    Found package "react-dom" at "./.yarn/__virtual__/react-dom-virtual-34fc0906e5/3/root/.yarn/berry/cache/react-dom-npm-18.2.0-dd675bca1c-8.zip/node_modules/react-dom/"
    Resolved "react-dom" via Yarn PnP to "/tmp/tmp.mfHdqKXG1S/.yarn/__virtual__/react-dom-virtual-34fc0906e5/3/root/.yarn/berry/cache/react-dom-npm-18.2.0-dd675bca1c-8.zip/node_modules/react-dom"
  The import "/tmp/tmp.mfHdqKXG1S/.yarn/__virtual__/react-dom-virtual-34fc0906e5/3/root/.yarn/berry/cache/react-dom-npm-18.2.0-dd675bca1c-8.zip/node_modules/react-dom" is being treated as an absolute path
  Attempting to load "/tmp/tmp.mfHdqKXG1S/.yarn/__virtual__/react-dom-virtual-34fc0906e5/3/root/.yarn/berry/cache/react-dom-npm-18.2.0-dd675bca1c-8.zip/node_modules/react-dom" as a file
    Checking for file "react-dom"
    Checking for file "react-dom.tsx"
    Checking for file "react-dom.ts"
    Checking for file "react-dom.jsx"
    Checking for file "react-dom.js"
    Checking for file "react-dom.css"
    Checking for file "react-dom.json"
    Failed to find file "react-dom"
  Attempting to load "/tmp/tmp.mfHdqKXG1S/.yarn/__virtual__/react-dom-virtual-34fc0906e5/3/root/.yarn/berry/cache/react-dom-npm-18.2.0-dd675bca1c-8.zip/node_modules/react-dom" as a directory
    Read 20 entries for directory "/"
    Read 20 entries for directory "/tmp/tmp.mfHdqKXG1S/.yarn/__virtual__/react-dom-virtual-34fc0906e5/3"
    Read 5 entries for directory "/tmp/tmp.mfHdqKXG1S/.yarn/__virtual__/react-dom-virtual-34fc0906e5/3/root"
    Read 1 entry for directory "/tmp/tmp.mfHdqKXG1S/.yarn/__virtual__/react-dom-virtual-34fc0906e5/3/root/.yarn"
    Read 2 entries for directory "/tmp/tmp.mfHdqKXG1S/.yarn/__virtual__/react-dom-virtual-34fc0906e5/3/root/.yarn/berry"
    Read 7 entries for directory "/tmp/tmp.mfHdqKXG1S/.yarn/__virtual__/react-dom-virtual-34fc0906e5/3/root/.yarn/berry/cache"
    Read 2 entries for directory "/tmp/tmp.mfHdqKXG1S/.yarn/__virtual__/react-dom-virtual-34fc0906e5/3/root/.yarn/berry/cache/react-dom-npm-18.2.0-dd675bca1c-8.zip"
    Read 2 entries for directory "/tmp/tmp.mfHdqKXG1S/.yarn/__virtual__/react-dom-virtual-34fc0906e5/3/root/.yarn/berry/cache/react-dom-npm-18.2.0-dd675bca1c-8.zip/node_modules"
    The file "/tmp/tmp.mfHdqKXG1S/.yarn/__virtual__/react-dom-virtual-34fc0906e5/3/root/.yarn/berry/cache/react-dom-npm-18.2.0-dd675bca1c-8.zip/node_modules/react-dom/package.json" exists
    Read 13 entries for directory "/tmp/tmp.mfHdqKXG1S/.yarn/__virtual__/react-dom-virtual-34fc0906e5/3/root/.yarn/berry/cache/react-dom-npm-18.2.0-dd675bca1c-8.zip/node_modules/react-dom"
    Searching for main fields in "/tmp/tmp.mfHdqKXG1S/.yarn/__virtual__/react-dom-virtual-34fc0906e5/3/root/.yarn/berry/cache/react-dom-npm-18.2.0-dd675bca1c-8.zip/node_modules/react-dom/package.json"
      Did not find main field "browser"
      Did not find main field "module"
      Found main field "main" with path "index.js"
        Checking for "index.js" in the "browser" map in
  "/tmp/tmp.mfHdqKXG1S/.yarn/__virtual__/react-dom-virtual-34fc0906e5/3/root/.yarn/berry/cache/react-dom-npm-18.2.0-dd675bca1c-8.zip/node_modules/react-dom/package.json"
          Checking for "index.js"
          Checking for "index.js.tsx"
          Checking for "index.js.ts"
          Checking for "index.js.jsx"
          Checking for "index.js.js"
          Checking for "index.js.css"
          Checking for "index.js.json"
          Checking for "index.js/index"
          Checking for "index.js/index.tsx"
          Checking for "index.js/index.ts"
          Checking for "index.js/index.jsx"
          Checking for "index.js/index.js"
          Checking for "index.js/index.css"
          Checking for "index.js/index.json"
        Checking for "./index.js" in the "browser" map in
  "/tmp/tmp.mfHdqKXG1S/.yarn/__virtual__/react-dom-virtual-34fc0906e5/3/root/.yarn/berry/cache/react-dom-npm-18.2.0-dd675bca1c-8.zip/node_modules/react-dom/package.json"
          Checking for "./index.js"
          Checking for "./index.js.tsx"
          Checking for "./index.js.ts"
          Checking for "./index.js.jsx"
          Checking for "./index.js.js"
          Checking for "./index.js.css"
          Checking for "./index.js.json"
          Checking for "./index.js/index"
          Checking for "./index.js/index.tsx"
          Checking for "./index.js/index.ts"
          Checking for "./index.js/index.jsx"
          Checking for "./index.js/index.js"
          Checking for "./index.js/index.css"
          Checking for "./index.js/index.json"
        Failed to find "index.js"
        Attempting to load "/tmp/tmp.mfHdqKXG1S/.yarn/__virtual__/react-dom-virtual-34fc0906e5/3/root/.yarn/berry/cache/react-dom-npm-18.2.0-dd675bca1c-8.zip/node_modules/react-dom/index.js" as a file
          Checking for file "index.js"
          Found file "index.js"
      Resolved to "/tmp/tmp.mfHdqKXG1S/.yarn/__virtual__/react-dom-virtual-34fc0906e5/3/root/.yarn/berry/cache/react-dom-npm-18.2.0-dd675bca1c-8.zip/node_modules/react-dom/index.js" using the "main" field in
  "/tmp/tmp.mfHdqKXG1S/.yarn/__virtual__/react-dom-virtual-34fc0906e5/3/root/.yarn/berry/cache/react-dom-npm-18.2.0-dd675bca1c-8.zip/node_modules/react-dom/package.json"
  Read 13 entries for directory "/tmp/tmp.mfHdqKXG1S/.yarn/__virtual__/react-dom-virtual-34fc0906e5/3/root/.yarn/berry/cache/react-dom-npm-18.2.0-dd675bca1c-8.zip/node_modules/react-dom"
  Primary path is "/tmp/tmp.mfHdqKXG1S/.yarn/__virtual__/react-dom-virtual-34fc0906e5/3/root/.yarn/berry/cache/react-dom-npm-18.2.0-dd675bca1c-8.zip/node_modules/react-dom/index.js" in namespace "file"

⬥ [VERBOSE] Resolving import "./cjs/react-dom.development.js" in directory "/tmp/tmp.mfHdqKXG1S/.yarn/__virtual__/react-dom-virtual-34fc0906e5/3/root/.yarn/berry/cache/react-dom-npm-18.2.0-dd675bca1c-8.zip/node_modules/react-dom" of type "require-call"

  Read 13 entries for directory "/tmp/tmp.mfHdqKXG1S/.yarn/__virtual__/react-dom-virtual-34fc0906e5/3/root/.yarn/berry/cache/react-dom-npm-18.2.0-dd675bca1c-8.zip/node_modules/react-dom"
  Read 13 entries for directory "/tmp/tmp.mfHdqKXG1S/.yarn/__virtual__/react-dom-virtual-34fc0906e5/3/root/.yarn/berry/cache/react-dom-npm-18.2.0-dd675bca1c-8.zip/node_modules/react-dom"
  Read 14 entries for directory "/tmp/tmp.mfHdqKXG1S/.yarn/__virtual__/react-dom-virtual-34fc0906e5/3/root/.yarn/berry/cache/react-dom-npm-18.2.0-dd675bca1c-8.zip/node_modules/react-dom/cjs"
  Checking for "cjs/react-dom.development.js" in the "browser" map in
  "/tmp/tmp.mfHdqKXG1S/.yarn/__virtual__/react-dom-virtual-34fc0906e5/3/root/.yarn/berry/cache/react-dom-npm-18.2.0-dd675bca1c-8.zip/node_modules/react-dom/package.json"
    Checking for "cjs/react-dom.development.js"
    Checking for "cjs/react-dom.development.js.tsx"
    Checking for "cjs/react-dom.development.js.ts"
    Checking for "cjs/react-dom.development.js.jsx"
    Checking for "cjs/react-dom.development.js.js"
    Checking for "cjs/react-dom.development.js.css"
    Checking for "cjs/react-dom.development.js.json"
    Checking for "cjs/react-dom.development.js/index"
    Checking for "cjs/react-dom.development.js/index.tsx"
    Checking for "cjs/react-dom.development.js/index.ts"
    Checking for "cjs/react-dom.development.js/index.jsx"
    Checking for "cjs/react-dom.development.js/index.js"
    Checking for "cjs/react-dom.development.js/index.css"
    Checking for "cjs/react-dom.development.js/index.json"
  Checking for "./cjs/react-dom.development.js" in the "browser" map in
  "/tmp/tmp.mfHdqKXG1S/.yarn/__virtual__/react-dom-virtual-34fc0906e5/3/root/.yarn/berry/cache/react-dom-npm-18.2.0-dd675bca1c-8.zip/node_modules/react-dom/package.json"
    Checking for "./cjs/react-dom.development.js"
    Checking for "./cjs/react-dom.development.js.tsx"
    Checking for "./cjs/react-dom.development.js.ts"
    Checking for "./cjs/react-dom.development.js.jsx"
    Checking for "./cjs/react-dom.development.js.js"
    Checking for "./cjs/react-dom.development.js.css"
    Checking for "./cjs/react-dom.development.js.json"
    Checking for "./cjs/react-dom.development.js/index"
    Checking for "./cjs/react-dom.development.js/index.tsx"
    Checking for "./cjs/react-dom.development.js/index.ts"
    Checking for "./cjs/react-dom.development.js/index.jsx"
    Checking for "./cjs/react-dom.development.js/index.js"
    Checking for "./cjs/react-dom.development.js/index.css"
    Checking for "./cjs/react-dom.development.js/index.json"
  Failed to find "cjs/react-dom.development.js"
  Attempting to load "/tmp/tmp.mfHdqKXG1S/.yarn/__virtual__/react-dom-virtual-34fc0906e5/3/root/.yarn/berry/cache/react-dom-npm-18.2.0-dd675bca1c-8.zip/node_modules/react-dom/cjs/react-dom.development.js" as a  file
    Checking for file "react-dom.development.js"
    Found file "react-dom.development.js"
  Read 14 entries for directory "/tmp/tmp.mfHdqKXG1S/.yarn/__virtual__/react-dom-virtual-34fc0906e5/3/root/.yarn/berry/cache/react-dom-npm-18.2.0-dd675bca1c-8.zip/node_modules/react-dom/cjs"
  Primary path is "/tmp/tmp.mfHdqKXG1S/.yarn/__virtual__/react-dom-virtual-34fc0906e5/3/root/.yarn/berry/cache/react-dom-npm-18.2.0-dd675bca1c-8.zip/node_modules/react-dom/cjs/react-dom.development.js" in
  namespace "file"

● [DEBUG] Resolving import "react" in directory "/tmp/tmp.mfHdqKXG1S/.yarn/__virtual__/react-dom-virtual-34fc0906e5/3/root/.yarn/berry/cache/react-dom-npm-18.2.0-dd675bca1c-8.zip/node_modules/react-dom/cjs" of type "require-call"

  Read 14 entries for directory "/tmp/tmp.mfHdqKXG1S/.yarn/__virtual__/react-dom-virtual-34fc0906e5/3/root/.yarn/berry/cache/react-dom-npm-18.2.0-dd675bca1c-8.zip/node_modules/react-dom/cjs"
  Checking for "react" in the "browser" map in
  "/tmp/tmp.mfHdqKXG1S/.yarn/__virtual__/react-dom-virtual-34fc0906e5/3/root/.yarn/berry/cache/react-dom-npm-18.2.0-dd675bca1c-8.zip/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.mfHdqKXG1S/.yarn/__virtual__/react-dom-virtual-34fc0906e5/3/root/.yarn/berry/cache/react-dom-npm-18.2.0-dd675bca1c-8.zip/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.mfHdqKXG1S/.yarn/__virtual__/react-dom-virtual-34fc0906e5/3/root/.yarn/berry/cache/react-dom-npm-18.2.0-dd675bca1c-8.zip/node_modules/react-dom/cjs"
    Parsed package name "react" and package subpath "."
    Checking for a package in the directory "/tmp/tmp.mfHdqKXG1S/.yarn/__virtual__/react-dom-virtual-34fc0906e5/3/root/.yarn/berry/cache/react-dom-npm-18.2.0-dd675bca1c-8.zip/node_modules/react"
    Read 2 entries for directory "/tmp/tmp.mfHdqKXG1S/.yarn/__virtual__/react-dom-virtual-34fc0906e5/3/root/.yarn/berry/cache/react-dom-npm-18.2.0-dd675bca1c-8.zip/node_modules"
    Failed to read directory "/tmp/tmp.mfHdqKXG1S/.yarn/__virtual__/react-dom-virtual-34fc0906e5/3/root/.yarn/berry/cache/react-dom-npm-18.2.0-dd675bca1c-8.zip/node_modules/react": no such file or directory
    Failed to read directory "/tmp/tmp.mfHdqKXG1S/.yarn/__virtual__/react-dom-virtual-34fc0906e5/3/root/.yarn/berry/cache/react-dom-npm-18.2.0-dd675bca1c-8.zip/node_modules/react"
    Attempting to load "/tmp/tmp.mfHdqKXG1S/.yarn/__virtual__/react-dom-virtual-34fc0906e5/3/root/.yarn/berry/cache/react-dom-npm-18.2.0-dd675bca1c-8.zip/node_modules/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"
      Checking for file "react.css"
      Checking for file "react.json"
      Failed to find file "react"
    Attempting to load "/tmp/tmp.mfHdqKXG1S/.yarn/__virtual__/react-dom-virtual-34fc0906e5/3/root/.yarn/berry/cache/react-dom-npm-18.2.0-dd675bca1c-8.zip/node_modules/react" as a directory
      Failed to read directory "/tmp/tmp.mfHdqKXG1S/.yarn/__virtual__/react-dom-virtual-34fc0906e5/3/root/.yarn/berry/cache/react-dom-npm-18.2.0-dd675bca1c-8.zip/node_modules/react"

✘ [ERROR] Could not resolve "react"

    .yarn/__virtual__/react-dom-virtual-34fc0906e5/3/root/.yarn/berry/cache/react-dom-npm-18.2.0-dd675bca1c-8.zip/node_modules/react-dom/cjs/react-dom.development.js:26:30:
      26 │           var React = require('react');
         ╵                               ~~~~~~~

  You can mark the path "react" as external to exclude it from the bundle, which will remove this
  error. You can also surround this "require" call with a try/catch block to handle this failure at
  run-time instead of bundle-time.

● [DEBUG] Resolving import "scheduler" in directory "/tmp/tmp.mfHdqKXG1S/.yarn/__virtual__/react-dom-virtual-34fc0906e5/3/root/.yarn/berry/cache/react-dom-npm-18.2.0-dd675bca1c-8.zip/node_modules/react-dom/cjs" of type "require-call"

  Read 14 entries for directory "/tmp/tmp.mfHdqKXG1S/.yarn/__virtual__/react-dom-virtual-34fc0906e5/3/root/.yarn/berry/cache/react-dom-npm-18.2.0-dd675bca1c-8.zip/node_modules/react-dom/cjs"
  Checking for "scheduler" in the "browser" map in
  "/tmp/tmp.mfHdqKXG1S/.yarn/__virtual__/react-dom-virtual-34fc0906e5/3/root/.yarn/berry/cache/react-dom-npm-18.2.0-dd675bca1c-8.zip/node_modules/react-dom/package.json"
    Checking for "scheduler"
    Checking for "scheduler.tsx"
    Checking for "scheduler.ts"
    Checking for "scheduler.jsx"
    Checking for "scheduler.js"
    Checking for "scheduler.css"
    Checking for "scheduler.json"
    Checking for "scheduler/index"
    Checking for "scheduler/index.tsx"
    Checking for "scheduler/index.ts"
    Checking for "scheduler/index.jsx"
    Checking for "scheduler/index.js"
    Checking for "scheduler/index.css"
    Checking for "scheduler/index.json"
  Checking for "./cjs/scheduler" in the "browser" map in
  "/tmp/tmp.mfHdqKXG1S/.yarn/__virtual__/react-dom-virtual-34fc0906e5/3/root/.yarn/berry/cache/react-dom-npm-18.2.0-dd675bca1c-8.zip/node_modules/react-dom/package.json"
    Checking for "./cjs/scheduler"
    Checking for "./cjs/scheduler/index"
  Failed to find "scheduler"
  Searching for "scheduler" in "node_modules" directories starting from
  "/tmp/tmp.mfHdqKXG1S/.yarn/__virtual__/react-dom-virtual-34fc0906e5/3/root/.yarn/berry/cache/react-dom-npm-18.2.0-dd675bca1c-8.zip/node_modules/react-dom/cjs"
    Parsed package name "scheduler" and package subpath "."
    Checking for a package in the directory "/tmp/tmp.mfHdqKXG1S/.yarn/__virtual__/react-dom-virtual-34fc0906e5/3/root/.yarn/berry/cache/react-dom-npm-18.2.0-dd675bca1c-8.zip/node_modules/scheduler"
    Read 2 entries for directory "/tmp/tmp.mfHdqKXG1S/.yarn/__virtual__/react-dom-virtual-34fc0906e5/3/root/.yarn/berry/cache/react-dom-npm-18.2.0-dd675bca1c-8.zip/node_modules"
    Failed to read directory "/tmp/tmp.mfHdqKXG1S/.yarn/__virtual__/react-dom-virtual-34fc0906e5/3/root/.yarn/berry/cache/react-dom-npm-18.2.0-dd675bca1c-8.zip/node_modules/scheduler": no such file or
  directory
    Failed to read directory "/tmp/tmp.mfHdqKXG1S/.yarn/__virtual__/react-dom-virtual-34fc0906e5/3/root/.yarn/berry/cache/react-dom-npm-18.2.0-dd675bca1c-8.zip/node_modules/scheduler"
    Attempting to load "/tmp/tmp.mfHdqKXG1S/.yarn/__virtual__/react-dom-virtual-34fc0906e5/3/root/.yarn/berry/cache/react-dom-npm-18.2.0-dd675bca1c-8.zip/node_modules/scheduler" as a file
      Checking for file "scheduler"
      Checking for file "scheduler.tsx"
      Checking for file "scheduler.ts"
      Checking for file "scheduler.jsx"
      Checking for file "scheduler.js"
      Checking for file "scheduler.css"
      Checking for file "scheduler.json"
      Failed to find file "scheduler"
    Attempting to load "/tmp/tmp.mfHdqKXG1S/.yarn/__virtual__/react-dom-virtual-34fc0906e5/3/root/.yarn/berry/cache/react-dom-npm-18.2.0-dd675bca1c-8.zip/node_modules/scheduler" as a directory
      Failed to read directory "/tmp/tmp.mfHdqKXG1S/.yarn/__virtual__/react-dom-virtual-34fc0906e5/3/root/.yarn/berry/cache/react-dom-npm-18.2.0-dd675bca1c-8.zip/node_modules/scheduler"

✘ [ERROR] Could not resolve "scheduler"

    .yarn/__virtual__/react-dom-virtual-34fc0906e5/3/root/.yarn/berry/cache/react-dom-npm-18.2.0-dd675bca1c-8.zip/node_modules/react-dom/cjs/react-dom.development.js:27:24:
      27 │ var Scheduler = require('scheduler');
         ╵                         ~~~~~~~~~~~

  You can mark the path "scheduler" as external to exclude it from the bundle, which will remove
  this error. You can also surround this "require" call with a try/catch block to handle this
  failure at run-time instead of bundle-time.

2 errors
node:child_process:866
    throw err;
    ^

Error: Command failed: /tmp/tmp.mfHdqKXG1S/.yarn/unplugged/esbuild-npm-0.15.2-e8a5300715/node_modules/esbuild/lib/pnpapi-esbuild-linux-64-esbuild --bundle --log-level=verbose ./foo.js
    at checkExecSyncError (node:child_process:828:11)
    at Object.execFileSync (node:child_process:863:15)
    at Object.<anonymous> (/tmp/tmp.mfHdqKXG1S/.yarn/unplugged/esbuild-npm-0.15.2-e8a5300715/node_modules/esbuild/bin/esbuild:177:28)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at Object.require$$0.Module._extensions..js (/tmp/tmp.mfHdqKXG1S/.pnp.cjs:9041:33)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.require$$0.Module._load (/tmp/tmp.mfHdqKXG1S/.pnp.cjs:8881:14)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12) {
  status: 1,
  signal: null,
  output: [ null, null, null ],
  pid: 346,
  stdout: null,
  stderr: null
}

Ref yarnpkg/berry#4732

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 enableGlobalCache true
yarn add esbuild@0.15.2 react@18.2.0 react-dom@18.2.0
printf "require('react-dom')" > foo.js
yarn esbuild --bundle --log-level=verbose ./foo.js
@merceyz merceyz changed the title pnp: esbuild@0.15.2 unable to resolve dependencies of a virtual dependency outside of the project directory pnp: esbuild@0.15.2 unable to resolve dependencies of virtual dependencies outside of the project directory Aug 12, 2022
@evanw
Copy link
Owner

evanw commented Aug 13, 2022

I assume I'm hitting this part of the specification:

Supporting this use case is difficult, as it requires a bookkeeping mechanism to track the manifests used to access modules, reusing them as much as possible and only looking for a new one when the chain breaks.

I'm supposed to track which manifest a given chain of imports comes from? What if the same file is imported from two separate manifests? Is the file supposed to be duplicated at that point so that the imports can potentially resolve to different things?

@arcanis
Copy link

arcanis commented Aug 13, 2022

What if the same file is imported from two separate manifests?

In Yarn each manifest has its own module cache, so in a bundler that would lead to the file being twice in the bundle.

I however can't think of a case where bundling sources from multiple manifests would be needed - perhaps it'd be easier, at least for the first iteration, to just call FIND_MANIFEST once, on the entry point, and use it for everything?

@evanw
Copy link
Owner

evanw commented Aug 13, 2022

Ok, I can change it to a singleton. There can be multiple entry points though. I can try to pick an approach for what to do in that situation.

@merceyz
Copy link
Author

merceyz commented Aug 14, 2022

I'm supposed to track which manifest a given chain of imports comes from?

If you keep track of all the manifests you've found then they keep track of it, you can then call FIND_LOCATOR on each manifest and see which one controls the path, if none of them controls the path then you check the filesystem (FIND_CLOSEST_PNP_MANIFEST).
Here is how we implement it (ref #2452 (comment))

What if the same file is imported from two separate manifests? Is the file supposed to be duplicated at that point so that the imports can potentially resolve to different things?

We throw an error in cases like that because we don't know which manifest to use.

@evanw
Copy link
Owner

evanw commented Aug 14, 2022

If you keep track of all the manifests you've found then they keep track of it, you can then call FIND_LOCATOR on each manifest and see which one controls the path, if none of them controls the path then you check the filesystem (FIND_CLOSEST_PNP_MANIFEST).

I'm not sure but I think this sounds like it could introduce non-determinism in the build because which manifest ends up being used for a given file would depend on what order the files were visited in. This might not matter for a deterministic traversal of the module graph but esbuild traverses the module graph in parallel so the order is non-deterministic.

@evanw evanw closed this as completed in 44a7a61 Aug 14, 2022
@evanw
Copy link
Owner

evanw commented Aug 14, 2022

I actually had to change this to be based on the current working directory instead of the entry point. Entry points are arbitrary strings and can sometimes not be file system paths at all (which can still be handled by plugins).

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

No branches or pull requests

3 participants