Electron报错:Invalid ‘main‘ field in ‘XXX\dist_electron\package.json‘ of ‘background.js‘

文章描述了在Electron项目中遇到DEP0128警告的问题,原因是package.json中的main字段无效。解决方法包括将dist_electron目录下的index.js重命名为background.js,并在vue.config.js中配置chainWebpackMainProcess,设置output.filename为background.js,以正确指定入口文件。

(node:4236) [DEP0128] DeprecationWarning: Invalid ‘main’ field in ‘E:\xxx\dist_electron\package.json’ of ‘background.js’. Please either fix that or report it to the module author
(Use electron --trace-deprecation ... to show where the warning was created)

解决方法 2步:

1.打包生成的 dist_electron 中 index.js 重命名为 background.js

 

2.根源解决 vue.config.js 中增加配置

chainWebpackMainProcess: (config) => {
   config.output.filename('background.js');
}

 

运行项目报错如下:D:\work\08\Substation_electron> npm run dev > substation-electron@1.0.0 dev > electron-vite dev vite v4.5.14 building for development... ✓ 3 modules transformed. Module format "cjs" does not support top-level await. Use the "es" or "system" output formats rather. file: D:/work/08/Substation_electron/src/main/store.js ✓ built in 40ms file:///D:/work/08/Substation_electron/node_modules/rollup/dist/es/shared/node-entry.js:2287 base = Object.assign(new Error(base.message), base); ^ Error [RollupError]: Module format "cjs" does not support top-level await. Use the "es" or "system" output formats rather. at error (file:///D:/work/08/Substation_electron/node_modules/rollup/dist/es/shared/node-entry.js:2287:30) at Module.render (file:///D:/work/08/Substation_electron/node_modules/rollup/dist/es/shared/node-entry.js:14056:20) at Chunk.renderModules (file:///D:/work/08/Substation_electron/node_modules/rollup/dist/es/shared/node-entry.js:16544:41) at Chunk.render (file:///D:/work/08/Substation_electron/node_modules/rollup/dist/es/shared/node-entry.js:16050:111) at file:///D:/work/08/Substation_electron/node_modules/rollup/dist/es/shared/node-entry.js:17682:72 at Array.map (<anonymous>) at renderChunks (file:///D:/work/08/Substation_electron/node_modules/rollup/dist/es/shared/node-entry.js:17682:53) at Bundle.generate (file:///D:/work/08/Substation_electron/node_modules/rollup/dist/es/shared/node-entry.js:17922:19) at async file:///D:/work/08/Substation_electron/node_modules/rollup/dist/es/shared/node-entry.js:26785:27 at async catchUnfinishedHookActions (file:///D:/work/08/Substation_electron/node_modules/rollup/dist/es/shared/node-entry.js:25910:16) { code: 'INVALID_TLA_FORMAT', id: 'D:/work/08/Substation_electron/src/main/store.js' } Node.js v20.19.3
08-14
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值