electron使用electron-forge打包后报错cannot find module ‘XXX’(An error cannot find module ‘xxx’ is reported when electron forge is used for packaging)


在写项目的时候,许多模块是全局安装,所以在本地使用没有问题,但是打包的时候不会打包全局安装的内容,因此打完包运行会出现cannot find module ‘ws’,cannot find module ‘express’等等错误。


npm i express.



1. After reporting an error, first think about why the module cannot be found. Enter the node of the current project_ After checking modules, the module with the current error report is indeed missing. Specifically, node_ The module name displayed in modules is: @ express

When writing a project, many modules are installed globally, so there is no problem using them locally, but the contents of the global installation will not be packaged when packaging. Therefore, errors such as cannot find module ‘WS’ and cannot find module’ express’ will appear after packaging.

2. Solution: install these modules in the project.

npm i express.

If you have any mistakes, please point them out. Thank you very much.