electron-vite / electron-vite-react

:electron: Electron + Vite + React + Sass boilerplate.
https://electron-vite.github.io
MIT License
1.92k stars 232 forks source link

[Bug] Error [ERR_REQUIRE_ESM]: require() of ES Module not supported. #203

Open clark-tan opened 8 months ago

clark-tan commented 8 months ago

Describe the bug

Error [ERR_REQUIRE_ESM]: require() of ES Module E:\test\electron-vite-react-main\dist-electron\main\index.js from E:\test\electron-vite-react-main\node_modules\electron\dist\resources\default_app.asar\main.js not supported.

我克隆下来更新了一下package.json,下面是我的包版本,运行起来后报错上面那个错误,请问应该怎么处理? node版本为v18.16.1

{ "name": "electron-vite-react", "version": "2.2.0", "main": "dist-electron/main/index.js", "description": "Electron Vite React boilerplate.", "author": "草鞋没号 308487730@qq.com", "license": "MIT", "private": true, "debug": { "env": { "VITE_DEV_SERVER_URL": "http://127.0.0.1:7777/" } }, "type": "module", "scripts": { "dev": "vite", "build": "tsc && vite build && electron-builder", "preview": "vite preview", "pree2e": "vite build --mode=test", "e2e": "playwright test" }, "dependencies": { "electron-updater": "6.1.7" }, "devDependencies": { "@playwright/test": "1.42.0", "@types/react": "18.2.60", "@types/react-dom": "18.2.19", "@vitejs/plugin-react": "4.2.1", "autoprefixer": "10.4.17", "electron": "22.3.12", "electron-builder": "24.12.0", "postcss": "8.4.35", "react": "^18.2.0", "react-dom": "^18.2.0", "tailwindcss": "^3.3.3", "typescript": "5.1.6", "vite": "5.0.10", "vite-plugin-electron": "^0.28.0", "vite-plugin-electron-renderer": "^0.14.5" } }

zacard-orc commented 8 months ago

+1 我碰到相同的问题,项目被type:module限制住了,但是一放开,还有很多地方要调整

caoxiemeihao commented 8 months ago

暂时来说,使用 "type": "module" 和整个 Node.js 的生态有很多不兼容的地方,尤其是 C/C++ 扩展。