alex8088 / electron-vite

Next generation Electron build tooling based on Vite 新一代 Electron 开发构建工具,支持源代码保护
https://electron-vite.org
MIT License
3.24k stars 139 forks source link

rimraf 6.0.1 or electron-store 10.0.0 can't be build correct with bytecodePlugin #573

Open AiHaibara opened 1 month ago

AiHaibara commented 1 month ago

Describe the bug

pnpm create @quick-start/electron testrimraf --template vue ✔ Add TypeScript? … Yes ✔ Add Electron updater plugin? … Yes ✔ Enable Electron download mirror proxy? … Yes add these lines in main/index.ts bottom

import { rimrafSync } from 'rimraf';
import { mkdirSync } from 'fs';
mkdirSync('aaa', {recursive: true});
rimrafSync('aaa');

rimraf 6.0.1 latest plugins: [externalizeDepsPlugin(),bytecodePlugin()] it will show when running the exe Uncaught Exception: TypeError: Class extends value undefined is not a constructor or null at Object.<anonymous> (/Users/xxx/code/projects/app/testrimraf/dist/mac-arm64/testrimraf.app/Contents/Resources/app.asar/node_modules/path-scurry/dist/commonjs/index.js:124:40) and if using plugins: [externalizeDepsPlugin({exclude:['rimraf']}),bytecodePlugin()] it will show when pnpm run build [vite:bytecode] unknown file: Unable to transform arrow inside class property

and it's working for run dev

pnpm create @quick-start/electron testelectronstore --template vue ✔ Add TypeScript? … Yes ✔ Add Electron updater plugin? … Yes ✔ Enable Electron download mirror proxy? … Yes add these lines in main/index.ts bottom

import Store from 'electron-store';
const store = new Store();

electron-store 10.0.0 latest plugins: [externalizeDepsPlugin(),bytecodePlugin()] it will show when running the exe or run dev Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/xxx/code/projects/app/testelectronstore/node_modules/.pnpm/electron-store@10.0.0/node_modules/electron-store/index.js from /Users/xxx/code/projects/app/testelectronstore/out/main/index.js not supported. and my project can't using type:module for other codes, here just for the demo case. but if using plugins: [externalizeDepsPlugin({exclude:['electron-store']}),bytecodePlugin()] it will show when pnpm run build [vite:bytecode] unknown file: Unable to transform arrow inside class property

Electron-Vite Version

2.3.0

Electron Version

31.0.2

Vite Version

5.3.1

Validations

alex8088 commented 1 month ago

Customizing Protection Or https://github.com/alex8088/electron-conf (Recommand)

AiHaibara commented 1 month ago

Customizing Protection Or https://github.com/alex8088/electron-conf (Recommand)

In the future, this 'esm' kind or 'arrow inside class property' packages may become more and more, will it support more convenient methods?

and for rimraf 6.0.1 plugins: [externalizeDepsPlugin()] want to ask a question do you know why running the exe and the error is like this? it will show when running the exe Uncaught Exception: TypeError: Class extends value undefined is not a constructor or null at Object.

Is it also caused by esm?, even the error he reported is not esm

AiHaibara commented 3 weeks ago

if i using manualChunks for process bytecodePlugin and if my child process using mime 4.0.4 I need to write like this

  if(id.includes('mime')){
            return 'xxx';
  }

otherwise it will exit the child process, i don't know why, just add this comment as a mark

{
  plugins: [externalizeDepsPlugin({exclude:['rimraf','mime']}),bytecodePlugin({chunkAlias:['index']})],
  build: {
    rollupOptions: {
      input: {
        index: resolve(__dirname, 'src/main/index.ts'),
        child: resolve(__dirname, 'src/main/child.ts')
      },
      output: {
        manualChunks(id){
          if(id.includes('mime')){
            return 'xxx';
          }
          if(id.includes('node_modules')){
            return 'vendor'
          }
        }
      }
    }
  }
}