yarnpkg / berry

πŸ“¦πŸˆ Active development trunk for Yarn βš’
https://yarnpkg.com
BSD 2-Clause "Simplified" License
7.45k stars 1.11k forks source link

[Bug?]: The locator that owns the path can't be found inside the dependency tree (this is probably an internal error) with webpack on Windows #6231

Open pigrammer3 opened 7 months ago

pigrammer3 commented 7 months ago

Self-service

Describe the bug

I was building a package with TypeScript and Webpack, and decided to migrate from 1.x to 4.x and PnP. I did so, and got the following error (trace anonymized) (this error is not from my real project, it's from the MRE below):

$ yarn webpack
C:\Users\pigrammer\project\.pnp.cjs:6919
      Error.captureStackTrace(firstError);
            ^

Error: Your application tried to access import-local, but it isn't declared in your dependencies; this makes the require call ambiguous and unsound.

Required package: import-local
Required by: C:\Users\pigrammer\project\.yarn\__virtual__\webpack-cli-virtual-7ee12da31b\3\AppData\Local\Yarn\Berry\cache\webpack-cli-npm-5.1.4-7be5b53b38-10c0.zip\node_modules\webpack-cli\bin\

Require stack:
- C:\Users\pigrammer\project\.yarn\__virtual__\webpack-cli-virtual-7ee12da31b\3\AppData\Local\Yarn\Berry\cache\webpack-cli-npm-5.1.4-7be5b53b38-10c0.zip\node_modules\webpack-cli\bin\cli.js
- C:\Users\pigrammer\project\.yarn\__virtual__\webpack-virtual-e455d0f00e\3\AppData\Local\Yarn\Berry\cache\webpack-npm-5.91.0-5571fb1057-10c0.zip\node_modules\webpack\bin\webpack.js
    at require$$0.Module._resolveFilename (C:\Users\pigrammer\project\.pnp.cjs:6919:13)
    at Module._load (node:internal/modules/cjs/loader:985:27)
    at require$$0.Module._load (C:\Users\pigrammer\project\.pnp.cjs:6810:31)
    at Module.require (node:internal/modules/cjs/loader:1235:19)
    at require (node:internal/modules/helpers:176:18)
    at Object.<anonymous> (C:\Users\pigrammer\project\.yarn\__virtual__\webpack-cli-virtual-7ee12da31b\3\AppData\Local\Yarn\Berry\cache\webpack-cli-npm-5.1.4-7be5b53b38-10c0.zip\node_modules\webpack-cli\bin\cli.js:5:21)
    at Module._compile (node:internal/modules/cjs/loader:1376:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1435:10)
    at require$$0.Module._extensions..js (C:\Users\pigrammer\project\.pnp.cjs:6962:33)
    at Module.load (node:internal/modules/cjs/loader:1207:32)

Node.js v20.10.0

I then ran yarn add --dev import-local to try to fix this, even though I did not actually use this package. I succeeded in getting a different error:

C:\Users\pigrammer\project\.pnp.cjs:6921
      Error.captureStackTrace(firstError);
            ^

Error: The locator that owns the "/C:/Users/pigrammer/project/Yarn/Berry/cache/import-local-npm-3.1.0-8960af5e51-10c0.zip/node_modules/import-local/" path can't be found inside the dependency tree (this is probably an internal error)
Require stack:
- C:\Users\pigrammer\project\.yarn\__virtual__\webpack-cli-virtual-7ee12da31b\3\AppData\Local\Yarn\Berry\cache\webpack-cli-npm-5.1.4-7be5b53b38-10c0.zip\node_modules\webpack-cli\bin\cli.js
- C:\Users\pigrammer\project\.yarn\__virtual__\webpack-virtual-e455d0f00e\3\AppData\Local\Yarn\Berry\cache\webpack-npm-5.91.0-5571fb1057-10c0.zip\node_modules\webpack\bin\webpack.js
    at require$$0.Module._resolveFilename (C:\Users\pigrammer\project\.pnp.cjs:6921:13)
    at Module._load (node:internal/modules/cjs/loader:985:27)
    at require$$0.Module._load (C:\Users\pigrammer\project\.pnp.cjs:6812:31)
    at Module.require (node:internal/modules/cjs/loader:1235:19)
    at require (node:internal/modules/helpers:176:18)
    at Object.<anonymous> (C:\Users\pigrammer\project\.yarn\__virtual__\webpack-cli-virtual-7ee12da31b\3\AppData\Local\Yarn\Berry\cache\webpack-cli-npm-5.1.4-7be5b53b38-10c0.zip\node_modules\webpack-cli\bin\cli.js:5:21)
    at Module._compile (node:internal/modules/cjs/loader:1376:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1435:10)
    at require$$0.Module._extensions..js (C:\Users\pigrammer\project\.pnp.cjs:6964:33)
    at Module.load (node:internal/modules/cjs/loader:1207:32)

Node.js v20.10.0

I would appreciate if this could be fixed.

To reproduce

Package.json:

{
  "name": "example",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "packageManager": "yarn@4.1.1",
  "devDependencies": {
    "import-local": "^3.1.0",
    "webpack": "^5.91.0",
    "webpack-cli": "^5.1.4"
  }
}

This happens the same whether I have webpack.config.js or whether I don't have it. It occurs even in an empty project with no source files.

Environment

System:
    OS: Windows 10 10.0.19045
    CPU: (4) x64 Intel(R) Core(TM) i5-5300U CPU @ 2.30GHz
  Binaries:
    Node: 20.10.0 - ~\AppData\Local\Temp\xfs-b058d8a7\node.CMD
    Yarn: 4.1.1 - ~\AppData\Local\Temp\xfs-b058d8a7\yarn.CMD
    npm: 10.2.5 - C:\Program Files\nodejs\npm.CMD

Additional context

No response

Domiii commented 2 months ago

I am having a similar problem when trying to install electron for a VSCode extension, also on Windows 10:

# This file contains the result of Yarn building a package (electron@npm:32.0.2)
# Script name: postinstall

c:\Users\user\code\my-project\.pnp.cjs:10764
      Error.captureStackTrace(firstError);
            ^

Error: The locator that owns the "/c:/Users/user/AppData/Local/Yarn/Berry/cache/extract-zip-npm-2.0.1-92a28e392b-10c0.zip/node_modules/extract-zip/" path can't be found inside the dependency tree (this is probably an internal error)
Require stack:
- c:\Users\user\code\my-project\.yarn\unplugged\electron-npm-32.0.2-869eb05173\node_modules\electron\install.js
    at require$$0.Module._resolveFilename (c:\Users\user\code\my-project\.pnp.cjs:10764:13)
    at Module._load (node:internal/modules/cjs/loader:1074:27)
    at require$$0.Module._load (c:\Users\user\code\my-project\.pnp.cjs:10655:31)
    at TracingChannel.traceSync (node:diagnostics_channel:315:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:217:24)
    at Module.require (node:internal/modules/cjs/loader:1339:12)
    at require (node:internal/modules/helpers:135:16)
    at Object.<anonymous> (c:\Users\user\code\my-project\.yarn\unplugged\electron-npm-32.0.2-869eb05173\node_modules\electron\install.js:9:17)
    at Module._compile (node:internal/modules/cjs/loader:1546:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1691:10)

Node.js v22.8.0
Domiii commented 2 months ago

Update: I was able to get it to work! πŸŽ‰

❌ Don't

  1. Don't run it from inside VSCode terminal, and also
  2. don't use bash (which ships with git on Windows).

I have seen both causing weird problems when installing things or resolving paths in the past. And this time it happened again.

βœ… Do