Skip to content

Commit

Permalink
Add a workaround for a Yarn v1 bug
Browse files Browse the repository at this point in the history
We cannot use `process-polyfill` as the package name due to a bug in Yarn v1. The errors results in a dependency conflict with `node-stdlib-browser` which fails to import `process/browser.js`.
yarnpkg/yarn#6907
  • Loading branch information
davidmyersdev committed Aug 22, 2023
1 parent 127d414 commit 094f979
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"@rollup/plugin-inject": "^5.0.3",
"buffer-polyfill": "npm:buffer@^6.0.3",
"node-stdlib-browser": "^1.2.0",
"process-polyfill": "npm:process@^0.11.10"
"process": "^0.11.10"
},
"peerDependencies": {
"vite": "^2.0.0 || ^3.0.0 || ^4.0.0"
Expand Down
6 changes: 3 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion shims/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
const global = globalThis || this || self

export { Buffer } from 'buffer-polyfill'
export { default as process } from 'process-polyfill'
// We cannot use `process-polyfill` as the package name due to a bug in Yarn v1. The errors results in a dependency
// conflict with `node-stdlib-browser` which fails to import `process/browser.js`.
// https://github.com/yarnpkg/yarn/issues/6907
export { default as process } from 'process'
export { global }
4 changes: 0 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,6 @@ export const nodePolyfills = (options: PolyfillOptions = {}): Plugin => {
if (isDevEnabled(optionsResolved.globals.Buffer) && /^(?:node:)?buffer$/.test(name)) {
return require.resolve('buffer-polyfill')
}

if (isDevEnabled(optionsResolved.globals.process) && /^(?:node:)?process$/.test(name)) {
return require.resolve('process-polyfill')
}
}

return {
Expand Down

0 comments on commit 094f979

Please sign in to comment.