Reproduction link or steps
Reproduction: https://github.com/psychobolt/svelte-yarn-pnp
- Setup plugin code in a Yarn PnP and TypeScript/Vite 8 project in a Windows Environment:
// import fs from 'node:fs';
// import { createRequire } from 'node:module';
import { fileURLToPath } from "node:url";
import type { Plugin } from "vite";
let mockerRuntimePath = fileURLToPath(
import.meta.resolve("storybook/internal/mocking-utils/mocker-runtime") // using Storybook package for testing
)
// const require = createRequire(import.meta.url);
// mockerRuntimePath = require.resolve("storybook/internal/mocking-utils/mocker-runtime");
function emitModuleFile(outputFilename: string): Plugin {
return {
name: 'emit-module-file',
async buildStart() {
try {
this.emitFile({
// type: 'asset',
// fileName: outputFilename,
// source: fs.readFileSync(mockerRuntimePath),
type: 'chunk',
id: mockerRuntimePath,
fileName: outputFilename
});
} catch (e) {
this.error(`Could not resolve or emit file for module id "storybook/internal/mocking-utils/mocker-runtime": ${e}`);
}
}
};
}
- Include in Vite config for library mode:
defineConfig({
plugins: [
emitModuleFile('vite-inject-mocker-entry.js')
]
lib: {
// ...
}
});
- Set
globalFolder in yarnrc.yml
enableGlobalCache: true
nodeLinker: pnp
globalFolder: D:/.yarn/berry
- Yarn Install and run the build e.g. (yarn build-mock)
What is expected?
File should be emitted without any issues.
What is actually happening?
vite v8.0.0 building client environment for production...
✗ Build failed in 174ms
error during build:
Build failed with 1 error:
[UNRESOLVED_ENTRY] Error: Cannot resolve entry module ../../.yarn/__virtual__/storybook-virtual-667f2f18d3/3/.yarn/berry/cache/storybook-npm-10.2.19-6054a8abd0-10c0.zip/node_modules/storybook/dist/mocking-utils/mocker-runtime.js.
at aggregateBindingErrorsIntoJsError (file:///D:/.yarn/berry/cache/rolldown-npm-1.0.0-rc.9-144204c709-10c0.zip/node_modules/rolldown/dist/shared/error-CP8smW_P.mjs:48:18)
at unwrapBindingResult (file:///D:/.yarn/berry/cache/rolldown-npm-1.0.0-rc.9-144204c709-10c0.zip/node_modules/rolldown/dist/shared/error-CP8smW_P.mjs:18:128)
at #build (file:///D:/.yarn/berry/cache/rolldown-npm-1.0.0-rc.9-144204c709-10c0.zip/node_modules/rolldown/dist/shared/rolldown-build-4YnQkA76.mjs:3311:34)
at async buildEnvironment (file:///D:/psychobolt-github/vite-storybook-boilerplate/.yarn/__virtual__/vite-virtual-cd4650cbff/3/.yarn/berry/cache/vite-npm-8.0.0-259ca3eb1b-10c0.zip/node_modules/vite/dist/node/chunks/node.js:32794:64)
at async Object.build (file:///D:/psychobolt-github/vite-storybook-boilerplate/.yarn/__virtual__/vite-virtual-cd4650cbff/3/.yarn/berry/cache/vite-npm-8.0.0-259ca3eb1b-10c0.zip/node_modules/vite/dist/node/chunks/node.js:33216:19)
at async Object.buildApp (file:///D:/psychobolt-github/vite-storybook-boilerplate/.yarn/__virtual__/vite-virtual-cd4650cbff/3/.yarn/berry/cache/vite-npm-8.0.0-259ca3eb1b-10c0.zip/node_modules/vite/dist/node/chunks/node.js:33213:153)
at async CAC.<anonymous> (file:///D:/psychobolt-github/vite-storybook-boilerplate/.yarn/__virtual__/vite-virtual-cd4650cbff/3/.yarn/berry/cache/vite-npm-8.0.0-259ca3eb1b-10c0.zip/node_modules/vite/dist/node/cli.js:778:3) {
errors: [Getter/Setter]
}
System Info
System:
OS: Windows 11 10.0.26200
CPU: (16) x64 AMD Ryzen 7 9800X3D 8-Core Processor
Memory: 13.27 GB / 31.08 GB
Binaries:
Node: 22.22.0 - C:\Program Files\nodejs\node.EXE
Yarn: 3.5.0 - C:\Program Files\nodejs\yarn.CMD
npm: 10.9.4 - C:\Program Files\nodejs\npm.CMD
pnpm: 7.29.1 - C:\Program Files\nodejs\pnpm.CMD
Browsers:
Chrome: 145.0.7632.160
Edge: Chromium (140.0.3485.54)
Internet Explorer: 11.0.26100.7309
Any additional comments?
- Might be a OS specific bug or drive issue, I have no issues if the global folder is on my main system C: drive or in same workspace folder (relative).
- Failing on
__virtual__ Yarn resolved paths, using import.meta.resolve and require.resolve
Reproduction link or steps
Reproduction: https://github.com/psychobolt/svelte-yarn-pnp
globalFolderinyarnrc.ymlWhat is expected?
File should be emitted without any issues.
What is actually happening?
System Info
System: OS: Windows 11 10.0.26200 CPU: (16) x64 AMD Ryzen 7 9800X3D 8-Core Processor Memory: 13.27 GB / 31.08 GB Binaries: Node: 22.22.0 - C:\Program Files\nodejs\node.EXE Yarn: 3.5.0 - C:\Program Files\nodejs\yarn.CMD npm: 10.9.4 - C:\Program Files\nodejs\npm.CMD pnpm: 7.29.1 - C:\Program Files\nodejs\pnpm.CMD Browsers: Chrome: 145.0.7632.160 Edge: Chromium (140.0.3485.54) Internet Explorer: 11.0.26100.7309Any additional comments?
__virtual__Yarn resolved paths, usingimport.meta.resolveandrequire.resolve