vkashti / patches / next-globals.js
next-globals.js
Raw

// Global patches for Next.js to fix common build errors
console.log('Applying Next.js global patches...');

// Fix for __non_webpack_require__ not defined
if (typeof global.__non_webpack_require__ === 'undefined') {
  global.__non_webpack_require__ = require;
  console.log('Patched global.__non_webpack_require__');
}

// Fix for missing process.env in some contexts
if (typeof process.env !== 'object') {
  process.env = {};
  console.log('Patched process.env');
}

// Fix for missing globalThis
if (typeof globalThis === 'undefined') {
  global.globalThis = global;
  console.log('Patched globalThis');
}

// Fix for eval not being available
if (typeof globalThis.eval !== 'function') {
  globalThis.eval = eval;
  console.log('Patched globalThis.eval');
}

// Other potential fixes can be added here

console.log('Next.js global patches applied successfully');