The way plugins and presets are loaded works with npm's hoisting, and even works in a non-monorepo (or where size-limit and its plugins are installed in the monorepo root), but does not work when size-limit is installed in a workspace with yarn pnp or pnpm with hoisting disabled.
Reproduction
With yarn:
-
Create a temporary directory and cd into it.
-
Create the following files:
package.json
{
"private": true,
"workspaces": [
"a"
]
}
a/index.js
Contents don't matter, even an empty file is ok.
a/package.json
{
"name": "a",
"devDependencies": {
"@size-limit/file": "^11.1.4",
"size-limit": "^11.1.4"
},
"size-limit": [
{
"path": "index.js"
}
],
"scripts": {
"size": "size-limit"
}
}
-
Run yarn set version stable && yarn install
-
Run yarn workspace a size
With pnpm:
-
Create a temporary directory and cd into it.
-
Create the following files:
package.json
.npmrc
pnpm-workspace.yaml
a/index.js
Contents don't matter, even an empty file is ok.
a/package.json
{
"name": "a",
"devDependencies": {
"@size-limit/file": "^11.1.4",
"size-limit": "^11.1.4"
},
"size-limit": [
{
"path": "index.js"
}
],
"scripts": {
"size": "size-limit"
}
}
-
Run pnpm install.
-
Run pnpm run --dir a size
Expected behavior
size-limit runs successfully.
Actual behavior
With yarn:
ERROR Error: size-limit tried to access @size-limit/file, but it isn't declared in its dependencies; this makes the require call ambiguous and unsound.
Required package: @size-limit/file (via "@size-limit/file/package.json")
Required by: size-limit@npm:11.1.4 (via /home/user/.yarn/berry/cache/size-limit-npm-11.1.4-dc2e299ec0-10c0.zip/node_modules/size-limit/load-plugins.js)
at makeError (/tmp/test/.pnp.cjs:6744:34)
at resolveToUnqualified (/tmp/test/.pnp.cjs:8392:21)
at Object.resolveToUnqualified (/tmp/test/.pnp.cjs:8572:26)
at resolve$1 (file:///tmp/test/.pnp.loader.mjs:2033:31)
at nextResolve (node:internal/modules/esm/hooks:866:28)
at Hooks.resolve (node:internal/modules/esm/hooks:304:30)
at MessagePort.handleMessage (node:internal/modules/esm/worker:196:24)
at [nodejs.internal.kHybridDispatch] (node:internal/event_target:825:20)
at MessagePort.<anonymous> (node:internal/per_context/messageport:23:28)
With pnpm:
$ pnpm run --dir a size
> a@ size /tmp/test/a
> size-limit
ERROR Error [ERR_MODULE_NOT_FOUND]: Cannot find package '@size-limit/file' imported from /tmp/test/node_modules/.pnpm/size-limit@11.1.4/node_modules/size-limit/load-plugins.js
at packageResolve (node:internal/modules/esm/resolve:854:9)
at moduleResolve (node:internal/modules/esm/resolve:927:18)
at defaultResolve (node:internal/modules/esm/resolve:1157:11)
at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:383:12)
at ModuleLoader.resolve (node:internal/modules/esm/loader:352:25)
at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:227:38)
at ModuleLoader.import (node:internal/modules/esm/loader:315:34)
at importModuleDynamically (node:internal/modules/esm/translators:161:31)
at importModuleDynamicallyCallback (node:internal/modules/esm/utils:222:14)
at file:///tmp/test/node_modules/.pnpm/size-limit@11.1.4/node_modules/size-limit/load-plugins.js:26:27
ELIFECYCLE Command failed with exit code 1.
The way plugins and presets are loaded works with npm's hoisting, and even works in a non-monorepo (or where size-limit and its plugins are installed in the monorepo root), but does not work when size-limit is installed in a workspace with yarn pnp or pnpm with hoisting disabled.
Reproduction
With yarn:
Create a temporary directory and cd into it.
Create the following files:
package.json
{ "private": true, "workspaces": [ "a" ] }a/index.js
Contents don't matter, even an empty file is ok.
a/package.json
{ "name": "a", "devDependencies": { "@size-limit/file": "^11.1.4", "size-limit": "^11.1.4" }, "size-limit": [ { "path": "index.js" } ], "scripts": { "size": "size-limit" } }Run
yarn set version stable && yarn installRun
yarn workspace a sizeWith pnpm:
Create a temporary directory and cd into it.
Create the following files:
package.json
{ }.npmrc
pnpm-workspace.yaml
a/index.js
Contents don't matter, even an empty file is ok.
a/package.json
{ "name": "a", "devDependencies": { "@size-limit/file": "^11.1.4", "size-limit": "^11.1.4" }, "size-limit": [ { "path": "index.js" } ], "scripts": { "size": "size-limit" } }Run
pnpm install.Run
pnpm run --dir a sizeExpected behavior
size-limitruns successfully.Actual behavior
With yarn:
With pnpm: