You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
The packaged file volume is too large and contains nodes_ modules electron-forge package (--template=vite) #3224
I agree to follow the code of conduct that this project uses.
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
Reacted by Ossama W. Obeid, strazi, JerryWu, Boris Berman and Fermin Coronel
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?
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.
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):
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?
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 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.
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.
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.
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.
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 you are correct. This assume you are not using anything like a native module that has to be "externalized". Same if you use squirrel, need to make sure that node module is included (NOT ignored) as well. Below is what I got working where I use Realm DB which is a native node module and has to be packaged as an external dependency.
Update this array with the dependencies you need to externalize: const NATIVE_MODULES_TO_PACKAGE = ['realm', 'electron-squirrel-startup'];
Note: this uses the flora-colossus library (created by @MarshallOfSound) to get the dependency tree of the native modules (since you need to also include the nested dependencies of the dependencies).
importtype{ForgeConfig}from'@electron-forge/shared-types';import{dirname}from'node:path';import{Walker,DepType,typeModule}from'flora-colossus';// any packages that you must mark as "external" in viteconstNATIVE_MODULES_TO_PACKAGE=['realm','electron-squirrel-startup'];constINCLUDE_NESTED_DEPS=trueasconst;letnativeModuleDependenciesToPackage: Set<string>;constconfig: ForgeConfig={// other config stuff...hooks: {prePackage: async(forgeConfig)=>{if(forgeConfig.packagerConfig.ignore!==undefined){thrownewError('forgeConfig.packagerConfig.ignore is already defined. Please remove it from your forge config and instead use the prePackage hook to dynamically set it.');}constgetExternalNestedDependencies=async(nodeModuleNames: string[],includeNestedDeps=true)=>{constfoundModules=newSet(nodeModuleNames);if(includeNestedDeps){for(constexternalofnodeModuleNames){typeMyPublicClass<T>={[PinkeyofT]: T[P];};typeMyPublicWalker=MyPublicClass<Walker>&{modules: Module[];walkDependenciesForModule: (moduleRoot: string,depType: DepType)=>Promise<void>;};constmoduleRoot=dirname(require.resolve(`${external}/package.json`,{paths: [__dirname]}));constwalker=newWalker(moduleRoot)asunknownasMyPublicWalker;walker.modules=[];awaitwalker.walkDependenciesForModule(moduleRoot,DepType.PROD);walker.modules.filter((dep)=>(dep.nativeModuleTypeasnumber)===DepType.PROD).map((dep)=>dep.name).forEach((name)=>foundModules.add(name));}}returnfoundModules;};nativeModuleDependenciesToPackage=awaitgetExternalNestedDependencies(NATIVE_MODULES_TO_PACKAGE,INCLUDE_NESTED_DEPS);forgeConfig.packagerConfig.ignore=(path)=>{// .vite bundled build filesif(path.startsWith('/.vite')){returnfalse;}// main package.json fileif(path==='/package.json'){returnfalse;}if(!path){returnfalse;}// need to first NOT ignore the root node_modules folderif(path==='/node_modules'){returnfalse;}// if path is in nativeModuleDependenciesToPackage, return false (to package it)constfoundModules: Set<string>=nativeModuleDependenciesToPackage;for(constmoduleoffoundModules){if(path.startsWith(`/node_modules/${module}`)||path.startsWith(`/node_modules/${module.split('/')[0]}`)){returnfalse;}}// for everything else, ignore itreturntrue;};},},// other config stuff...};
Hi all, I too am plagued with this issue even in latest 7.2.x release. this is a huge security risk and should be fixed as soon as possible.
Is there anyone who is working on this issue or any other update?
I will really be very thankful to the team if this gets fixed. @BlackHole1 @caoxiemeihao
Hi @akash07k. I recently communicated with @caoxiemeihao. He is currently looking for a new job, so he temporarily doesn’t have extra time to address the related PR. However, he also mentioned that once his job is stable, he will refocus on these issues.
Oh, I see.
I wish him all the very best for the new job and I hope he gets it soon. :-)
Hi @akash07k. I recently communicated with @caoxiemeihao. He is currently looking for a new job, so he temporarily doesn’t have extra time to address the related PR. However, he also mentioned that once his job is stable, he will refocus on these issues.
I'm about to fix this issue and have been stuck on CI for a few days.
BTW, I know the specific reason for the CI error, I have temporarily resolved it, and I will try to completely fix the CI error in the next upgrade of Vite5 PR (it is coming soon).
Reacted by Akash Kakkar, Ryan Hoffman, Kevin Cui, Edy and M.cat
I'm about to fix this issue and have been stuck on CI for a few days.
BTW, I know the specific reason for the CI error, I have temporarily resolved it, and I will try to completely fix the CI error in the next upgrade of Vite5 PR (it is coming soon).
Activity
owo commentedon May 18, 2023
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.vitebeing used?MDransfeld commentedon Jun 16, 2023
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.
jbtobar commentedon Jul 3, 2023
yes, seeing this too (6.2.1)
caoxiemeihao commentedon Jul 4, 2023
Can you provide a specific repository for replication? Maybe you put most of the packages in
dependencies.jbtobar commentedon Jul 4, 2023
it happens with the template repository, no modifications:
I am on mac, the
my-new-app/out/my-new-app-darwin-x64/my-new-app.app/Contents/Resources/applooks like this: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.asarlooks like this (the node_modules folder is empty):GitMurf commentedon Jul 14, 2023
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?
jbtobar commentedon Jul 14, 2023
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.
GitMurf commentedon Jul 14, 2023
@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.
jbtobar commentedon Jul 14, 2023
I am using the webpack typescript template with electron-forge v
^6.0.4and 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/vitemight be where the issue is.jbtobar commentedon Jul 15, 2023
@GitMurf the current webpack template does work correctly btw.
jbtobar commentedon Jul 15, 2023
This also sounds related: #2175
bermanboris commentedon Jul 15, 2023
Is there any temporary fix to this issue?
jbtobar commentedon Jul 15, 2023
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.
2 remaining items
GitMurf commentedon Jul 16, 2023
So is the idea here that this is ignoring everything except .Vite and package.Json?
GitMurf commentedon Jul 18, 2023
This also appears related: #1250
GitMurf commentedon Jul 18, 2023
ok yep this ignore function is in webpack plugin but not in vite plugin:
forge/packages/plugin/webpack/src/WebpackPlugin.ts
Line 202 in c7a6891
cc @caoxiemeihao
ht-sauce commentedon Aug 8, 2023
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.
BlackHole1 commentedon Aug 8, 2023
@caoxiemeihao PTAL
caoxiemeihao commentedon Aug 9, 2023
@GitMurf @ht-sauce Okay!
Thx for helps, I'll back in the week end!
GitMurf commentedon Aug 9, 2023
@ht-sauce you are correct. This assume you are not using anything like a native module that has to be "externalized". Same if you use squirrel, need to make sure that node module is included (NOT ignored) as well. Below is what I got working where I use Realm DB which is a native node module and has to be packaged as an external dependency.
cc @caoxiemeihao I recommend doing testing using something like Realm (https://github.com/realm/realm-js) as a way to validate external dependencies work as well :)
Update this array with the dependencies you need to externalize:
const NATIVE_MODULES_TO_PACKAGE = ['realm', 'electron-squirrel-startup'];Note: this uses the
flora-colossuslibrary (created by @MarshallOfSound) to get the dependency tree of the native modules (since you need to also include the nested dependencies of the dependencies).Hope this helps!
akash07k commentedon Dec 9, 2023
Hi all, I too am plagued with this issue even in latest 7.2.x release. this is a huge security risk and should be fixed as soon as possible.
Is there anyone who is working on this issue or any other update?
I will really be very thankful to the team if this gets fixed.
@BlackHole1
@caoxiemeihao
akash07k commentedon Dec 9, 2023
Also related #3377 also highlights how big this is a risk for security
BlackHole1 commentedon Dec 11, 2023
Hi @akash07k. I recently communicated with @caoxiemeihao. He is currently looking for a new job, so he temporarily doesn’t have extra time to address the related PR. However, he also mentioned that once his job is stable, he will refocus on these issues.
akash07k commentedon Dec 11, 2023
Oh, I see.
I wish him all the very best for the new job and I hope he gets it soon. :-)
caoxiemeihao commentedon Jan 8, 2024
@akash07k Hey! 👋
I'm about to fix this issue and have been stuck on CI for a few days.
BTW, I know the specific reason for the CI error, I have temporarily resolved it, and I will try to completely fix the CI error in the next upgrade of Vite5 PR (it is coming soon).
akash07k commentedon Jan 8, 2024
Thanks so much @caoxiemeihao, I'll be waiting for the update. :-)
caoxiemeihao commentedon Jan 17, 2024
Fixed in #3336