davidmyersdev / vite-plugin-node-polyfills

A Vite plugin to polyfill Node's Core Modules for browser environments.
MIT License
263 stars 17 forks source link

Require is not wrong, but it seems that there is no effect #15

Closed Soltus closed 1 year ago

Soltus commented 1 year ago

error:

index.js:8 Uncaught TypeError: Cannot read properties of null (reading 'existsSync')
    at getElectronPath (index.js:8:10)
    at node_modules/.pnpm/registry.npmmirror.com+electron@23.0.0-beta.8/node_modules/electron/index.js (index.js:21:18)
    at __require2 (chunk-SR54VZQL.js?v=2c462924:18:50)
    at electron.js?v=2c462924:7:16

index.js from electron node_module:

const fs = require('fs');
const path = require('path');

const pathFile = path.join(__dirname, 'path.txt');

function getElectronPath () {
  let executablePath;
  if (fs.existsSync(pathFile)) {
    executablePath = fs.readFileSync(pathFile, 'utf-8');
  }
  if (process.env.ELECTRON_OVERRIDE_DIST_PATH) {
    return path.join(process.env.ELECTRON_OVERRIDE_DIST_PATH, executablePath || 'electron');
  }
  if (executablePath) {
    return path.join(__dirname, 'dist', executablePath);
  } else {
    throw new Error('Electron failed to install correctly, please delete node_modules/electron and try installing again');
  }
}

module.exports = getElectronPath();

env:

"vite": "^4.1.1",
"vite-plugin-node-polyfills": "^0.7.0",
"electron": "23.0.0-beta.8",
davidmyersdev commented 1 year ago

This is related to #18 and is not actually an issue with this package.