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.4 unable to resolve workspaces #2476

Closed
merceyz opened this issue Aug 16, 2022 · 2 comments
Closed

pnp: esbuild@0.15.4 unable to resolve workspaces #2476

merceyz opened this issue Aug 16, 2022 · 2 comments

Comments

@merceyz
Copy link

merceyz commented Aug 16, 2022

Describe the bug

6a69a18 introduced a regression that prevents esbuild from resolving workspaces.

✘ [ERROR] Could not resolve "foo"

    index.js:1:7:
      1 │ import 'foo'
        │        ~~~~~
        ╵        "./foo"

  Use the relative path "./foo" to reference the file "foo/index.js". Without the leading "./", the
  path "foo" is being interpreted as a package path instead.

1 error
node:child_process:866
    throw err;
    ^

Error: Command failed: /tmp/tmp.d9yLfGFMsp/.yarn/unplugged/esbuild-npm-0.15.4-228a903ba9/node_modules/esbuild/lib/pnpapi-esbuild-linux-64-esbuild --bundle ./index.js
    at checkExecSyncError (node:child_process:828:11)
    at Object.execFileSync (node:child_process:863:15)
    at Object.<anonymous> (/tmp/tmp.d9yLfGFMsp/.yarn/unplugged/esbuild-npm-0.15.4-228a903ba9/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.d9yLfGFMsp/.pnp.cjs:8990:33)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.require$$0.Module._load (/tmp/tmp.d9yLfGFMsp/.pnp.cjs:8830:14)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12) {
  status: 1,
  signal: null,
  output: [ null, null, null ],
  pid: 564,
  stdout: null,
  stderr: null
}

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
printf '{"workspaces": ["./foo"], "dependencies": {"foo": "workspace:*"}}' > package.json
mkdir foo
printf '{"name": "foo"}' > foo/package.json
printf 'console.log(42)' > foo/index.js
printf "import 'foo'" > index.js
yarn add esbuild@0.15.4
yarn esbuild --bundle ./index.js
@evanw
Copy link
Owner

evanw commented Aug 17, 2022

In case you're curious, my fix for this issue looks something like this:

  • Modify RESOLVE_TO_UNQUALIFIED to return path.resolve(manifest.dirPath, dependencyPkg.packageLocation) and modulePath separately, with the result of path.resolve stored in pkgDirPath
  • Set absModulePath to path.join(pkgDirPath, modulePath)
  • Check for package.json in pkgDirPath
    • If package.json was found and the exports field exists
      • Run PACKAGE_EXPORTS_RESOLVE(pkgDirPath, modulePath, pjson.exports, defaultConditions) from node's specification
    • If package.json was found and the browser field exists
      • Interpret the browser mapping on the result of absModulePath (since esbuild is a bundler)
  • Try running LOAD_AS_FILE(absModulePath) from node's specification
  • Try running LOAD_AS_DIRECTORY(absModulePath) from node's specification
  • Fail if we get here

@merceyz
Copy link
Author

merceyz commented Aug 17, 2022

Thanks, I'll ping @arcanis for potential spec changes.

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

2 participants