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

1.报错后先思考为什么会找不到模块。进入当前项目的node_modules查看后,果然缺失了当前报错的模块。具体表现为,node_modules中显示的模块名字为:@express

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

2.解决:将这些模块安装在项目中。

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.