forge icon indicating copy to clipboard operation
forge copied to clipboard

The packaged file volume is too large and contains nodes_ modules electron-forge package (--template=vite)

Open jinye123 opened this issue 3 years ago • 29 comments

Pre-flight checklist

  • [X] I have read the contribution documentation for this project.
  • [X] I agree to follow the code of conduct that this project uses.
  • [X] I have searched the issue tracker for a bug that matches the one I want to file, without success.

Electron Forge version

6.1.1

Electron version

24.1.2

Operating system

macOs 12.2.1

Last known working Electron Forge version

6.1.1

Expected behavior

yarn create electron-app my-new-app --template=vite and run electron-forga package The packaged file volume is too large and contains nodes_ modules in out =>app =>resource

Actual behavior

yarn create electron-app my-new-app --template=vite and run electron-forga package The packaged file volume is too large and contains nodes_ modules in out =>app =>resource

Steps to reproduce

yarn create electron-app my-new-app --template=vite npm run package

Additional information

No response

jinye123 avatar Apr 28 '23 03:04 jinye123

In addition to node_modules, the actual source code is being included in the app directory. Why aren't the compiled and minified files in .vite being used?

owo avatar May 18 '23 18:05 owo

This still happens with version 6.2.1, the whole source folder including the node_modules folder is copied to resources/app. Instead only the .vite folder should be copied.

MDransfeld avatar Jun 16 '23 08:06 MDransfeld

yes, seeing this too (6.2.1)

jbtobar avatar Jul 03 '23 16:07 jbtobar

Can you provide a specific repository for replication? Maybe you put most of the packages in dependencies.

caoxiemeihao avatar Jul 04 '23 05:07 caoxiemeihao

it happens with the template repository, no modifications:

yarn create electron-app my-new-app --template=vite
cd my-new-app
yarn package

I am on mac, the my-new-app/out/my-new-app-darwin-x64/my-new-app.app/Contents/Resources/app looks like this:

.
├── .gitignore
├── .vite
│   ├── build
│   │   ├── main.js
│   │   └── preload.js
│   └── renderer
│       └── main_window
│           ├── assets
│           │   ├── index-620ac58a.css
│           │   └── index-f38d6f86.js
│           └── index.html
├── forge.config.js
├── index.html
├── node_modules
│   ├── .yarn-integrity
│   ├── @electron
│   ├── @electron-forge
│   ├── @esbuild
│   ├── @isaacs
│   ├── @malept
│   ├── @nodelib
│   ├── @npmcli
│   ├── @pkgjs
│   ├── @sindresorhus
│   ├── @szmarczak
│   ├── @tootallnate
│   ├── @types
│   └── electron-squirrel-startup
│       ├── .eslintrc
│       ├── .jsfmtrc
│       ├── .npmignore
│       ├── .travis.yml
│       ├── LICENSE
│       ├── README.md
│       ├── appveyor.yml
│       ├── index.js
│       ├── node_modules
│       │   ├── debug
│       │   │   ├── .coveralls.yml
│       │   │   ├── .eslintrc
│       │   │   ├── .npmignore
│       │   │   ├── .travis.yml
│       │   │   ├── CHANGELOG.md
│       │   │   ├── LICENSE
│       │   │   ├── Makefile
│       │   │   ├── README.md
│       │   │   ├── component.json
│       │   │   ├── karma.conf.js
│       │   │   ├── node.js
│       │   │   ├── package.json
│       │   │   └── src
│       │   │       ├── browser.js
│       │   │       ├── debug.js
│       │   │       ├── index.js
│       │   │       ├── inspector-log.js
│       │   │       └── node.js
│       │   └── ms
│       │       ├── index.js
│       │       ├── license.md
│       │       ├── package.json
│       │       └── readme.md
│       ├── package.json
│       └── test
│           ├── index.test.js
│           └── mocha.opts
├── package.json
├── src
│   ├── index.css
│   ├── main.js
│   ├── preload.js
│   └── renderer.js
├── vite.main.config.mjs
├── vite.preload.config.mjs
└── vite.renderer.config.mjs

25 directories, 49 files

and for example, on a previous project where I used webpack, the my-new-app/out/my-new-app-darwin-x64/my-new-app.app/Contents/Resources/app.asar looks like this (the node_modules folder is empty):

image

jbtobar avatar Jul 04 '23 11:07 jbtobar

Any word on this? I noticed the same thing. All of our source code is bundled up with the package. It more or less appears as if the build advantages of vite using rollup etc. is nullified as the packaged app is not tree shook, not bundled to the few main.js/preload.js etc. and not minified / obfuscated (code of our app can easily be read by users).

It almost seems as if the regular electron-forge package/make procedure is being used and ignoring vite/rollup. Anyone have any thoughts?

GitMurf avatar Jul 14 '23 06:07 GitMurf

its also quite a security vulnerability because the entire source code is copied into the release, so users who use this template and then distribute the app would be distributing their entire repo without realizing.

not sure who is in charge on this (@BlackHole1 @caoxiemeihao ) but maybe maintainers might want to remove this template until fixed or warn users.

jbtobar avatar Jul 14 '23 17:07 jbtobar

@jbtobar I know the vite template was based on the webpack template... do you know if the webpack template (with and/or without TypeScript) is packaging correctly? I am not a webpack guy so have never used it.

GitMurf avatar Jul 14 '23 21:07 GitMurf

I am using the webpack typescript template with electron-forge v ^6.0.4 and it has been packaging correctly. I haven't tested the latest version but my guess is it should package correctly as well.

I am not familiar with the forge repo but from quick glancing I think forge/packages/plugin/vite might be where the issue is.

jbtobar avatar Jul 14 '23 22:07 jbtobar

@GitMurf the current webpack template does work correctly btw.

jbtobar avatar Jul 15 '23 16:07 jbtobar

This also sounds related: https://github.com/electron/forge/pull/2175

jbtobar avatar Jul 15 '23 16:07 jbtobar

Is there any temporary fix to this issue?

bermanboris avatar Jul 15 '23 17:07 bermanboris

I am trying to figure one out. I have been trying to play with these hooks (postStart packageAfterCopy packageAfterPrune packageAfterExtract prePackage postPackage ignore )

in the forge.config but no dice. Now playing with the source code to figure out the issue. @erickzhao or anyone familiar with electron-forge code base maybe knows something.

jbtobar avatar Jul 15 '23 17:07 jbtobar

this direction is giving me results btw:

packagerConfig: {
      ignore: (path) => {
          if (path.startsWith('/.vite')) return false;
          if (path === '/package.json') return false;
          if (!path) return false;
          return true;
      },
  },

jbtobar avatar Jul 15 '23 18:07 jbtobar

@bermanboris fyi the above dirty hack doesn't package electron-squirrel-startup so there's that. Still trying to figure out how to make this work. Hopefully @caoxiemeihao can offer some clarity.

jbtobar avatar Jul 15 '23 20:07 jbtobar

this direction is giving me results btw:

So is the idea here that this is ignoring everything except .Vite and package.Json?

GitMurf avatar Jul 16 '23 04:07 GitMurf

This also appears related: https://github.com/electron/forge/issues/1250

GitMurf avatar Jul 18 '23 03:07 GitMurf

ok yep this ignore function is in webpack plugin but not in vite plugin: https://github.com/electron/forge/blob/c7a68918cf6f99f85e07c4c63f0965e72a76b4a3/packages/plugin/webpack/src/WebpackPlugin.ts#L202

cc @caoxiemeihao

GitMurf avatar Jul 18 '23 04:07 GitMurf

this direction is giving me results btw:

packagerConfig: {
      ignore: (path) => {
          if (path.startsWith('/.vite')) return false;
          if (path === '/package.json') return false;
          if (!path) return false;
          return true;
      },
  },

This function cannot identify the code in the nodejs section of the main process, and will remove the dependent packages in the main process that should not be ignored. This function has a bug My main process relies on a specific package file, which has resulted in the package being removed, but the path address was not returned correctly. That is to say, it is ignored by default.

ht-sauce avatar Aug 08 '23 11:08 ht-sauce

@caoxiemeihao PTAL

BlackHole1 avatar Aug 08 '23 14:08 BlackHole1