Comments (2)
Maybe dupe of #71 ?
from vite-plugin-node-polyfills.
If anyone is facing this, In our app we are in the process of migrating from create-react-app
to Vite and I created this package patch (it's for v0.21.0 only) as an interim solution.
diff --git a/node_modules/vite-plugin-node-polyfills/dist/index.cjs b/node_modules/vite-plugin-node-polyfills/dist/index.cjs
index fef08f0..13aefe5 100644
--- a/node_modules/vite-plugin-node-polyfills/dist/index.cjs
+++ b/node_modules/vite-plugin-node-polyfills/dist/index.cjs
@@ -1,3 +1,3 @@
-"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const _=require("node:module"),y=require("@rollup/plugin-inject"),B=require("node-stdlib-browser"),x=require("node-stdlib-browser/helpers/rollup/plugin"),P=require("node-stdlib-browser/helpers/esbuild/plugin");var a=typeof document<"u"?document.currentScript:null;const d=e=>e&&e.__esModule?e:{default:e},T=d(y),j=d(B),q=d(P),b=(e,r)=>p(e)===p(r),i=(e,r)=>e?e===!0?!0:e===r:!1,R=e=>e.startsWith("node:"),S=e=>{const r=e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");return new RegExp(`^${r}$`)},p=e=>e.replace(/^node:/,""),g=["import __buffer_polyfill from 'vite-plugin-node-polyfills/shims/buffer'","import __global_polyfill from 'vite-plugin-node-polyfills/shims/global'","import __process_polyfill from 'vite-plugin-node-polyfills/shims/process'","","globalThis.Buffer = globalThis.Buffer || __buffer_polyfill","globalThis.global = globalThis.global || __global_polyfill","globalThis.process = globalThis.process || __process_polyfill",""].join(`
+"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const _=require("node:module"),y=require("@rollup/plugin-inject"),B=require("node-stdlib-browser"),x=require("node-stdlib-browser/helpers/rollup/plugin"),P=require("node-stdlib-browser/helpers/esbuild/plugin");var a=typeof document<"u"?document.currentScript:null;const d=e=>e&&e.__esModule?e:{default:e},T=d(y),j=d(B),q=d(P),b=(e,r)=>p(e)===p(r),i=(e,r)=>e?e===!0?!0:e===r:!1,R=e=>e.startsWith("node:"),S=e=>{const r=e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");return new RegExp(`^${r}$`)},p=e=>e.replace(/^node:/,""),g=["import __buffer_polyfill from 'vite-plugin-node-polyfills/shims/buffer'","import __global_polyfill from 'vite-plugin-node-polyfills/shims/global'","import __process_polyfill from 'vite-plugin-node-polyfills/shims/process'","","globalThis.Buffer = globalThis.Buffer || __buffer_polyfill","globalThis.global = globalThis.global || __global_polyfill","globalThis.process = globalThis.process?.env ? { ...__process_polyfill, env: globalThis.process.env } : __process_polyfill",""].join(`
`),$=(e={})=>{const r=_.createRequire(typeof document>"u"?require("url").pathToFileURL(__filename).href:a&&a.src||new URL("index.cjs",document.baseURI).href),f=[r.resolve("vite-plugin-node-polyfills/shims/buffer"),r.resolve("vite-plugin-node-polyfills/shims/global"),r.resolve("vite-plugin-node-polyfills/shims/process")],l={include:[],exclude:[],overrides:{},protocolImports:!0,...e,globals:{Buffer:!0,global:!0,process:!0,...e.globals}},v=o=>l.include.length>0?!l.include.some(s=>b(o,s)):l.exclude.some(s=>b(o,s)),m=o=>{if(i(l.globals.Buffer,"dev")&&/^buffer$/.test(o))return"vite-plugin-node-polyfills/shims/buffer";if(i(l.globals.global,"dev")&&/^global$/.test(o))return"vite-plugin-node-polyfills/shims/global";if(i(l.globals.process,"dev")&&/^process$/.test(o))return"vite-plugin-node-polyfills/shims/process";if(o in l.overrides)return l.overrides[o]},c=Object.entries(j.default).reduce((o,[s,t])=>(!l.protocolImports&&R(s)||v(s)||(o[s]=m(p(s))||t),o),{});return{name:"vite-plugin-node-polyfills",config:(o,s)=>{const t=s.command==="serve";return{build:{rollupOptions:{onwarn:(n,u)=>{x.handleCircularDependancyWarning(n,()=>{if(o.build?.rollupOptions?.onwarn)return o.build.rollupOptions.onwarn(n,u);u(n)})},plugins:[{...T.default({...i(l.globals.Buffer,"build")?{Buffer:"vite-plugin-node-polyfills/shims/buffer"}:{},...i(l.globals.global,"build")?{global:"vite-plugin-node-polyfills/shims/global"}:{},...i(l.globals.process,"build")?{process:"vite-plugin-node-polyfills/shims/process"}:{}})}]}},esbuild:{banner:t?g:void 0},optimizeDeps:{exclude:[...f],esbuildOptions:{banner:t?{js:g}:void 0,define:{...t&&i(l.globals.Buffer,"dev")?{Buffer:"Buffer"}:{},...t&&i(l.globals.global,"dev")?{global:"global"}:{},...t&&i(l.globals.process,"dev")?{process:"process"}:{}},inject:[...f],plugins:[q.default(c),{name:"vite-plugin-node-polyfills-shims-resolver",setup(n){for(const u of f){const h=S(u);n.onResolve({filter:h},()=>({external:!1,path:u}))}}}]}},resolve:{alias:{...c}}}}}};exports.nodePolyfills=$;
//# sourceMappingURL=index.cjs.map
from vite-plugin-node-polyfills.
Related Issues (20)
- Bug: TypeError: util.inherits is not a function at node_modules/@microsoft/signalr-protocol-msgpack/dist/cjs/MessagePackHubProtocol.js (MessagePackHubProtocol.ts:5:1) HOT 1
- Bug: require is not defined using Remix Vite HOT 3
- Bug: Cannot destructure property 'Uint8Array' of 'globalThis' as it is undefined. HOT 2
- .
- Failed to resolve import "vite-plugin-node-polyfills/shims/buffer" HOT 15
- Error when having type: module in package.json HOT 1
- Cannot access "fs/promises.readFile" in client code.
- bug: config `include: [],` treated as `no option is passed`
- Globals are always defined HOT 1
- Bug: conflict with another middleware plugin HOT 4
- Bug: PassThrough is not exported by "__vite-browser-external" during build HOT 1
- Bug: exports is not defined HOT 2
- Bug: importing 'crypto' polyfill leads to error `exports is not defined` with yarn build && yarn preview in nuxt HOT 7
- Bug: `node:assert/strict` is not polyfilled
- Bug: Cannot destructure property 'existsSync' of 'require_empty(...) HOT 4
- TypeError: undefined is not an object (evaluating 'process.version.slice') HOT 1
- Bug: How to use crypto.X509Certificate
- Bug: cannot polyfill the node process?
- exclude polyfills for specific dependencies HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vite-plugin-node-polyfills.