(base) songjunwei@songjunweideMacBook-Pro viefong-pc % yarn build:main
yarn run v1.22.21
$ cross-env NODE_ENV=production TS_NODE_TRANSPILE_ONLY=true webpack --config ./electron/.erb/configs/webpack.config.main.prod.ts
ERROR in ./node_modules/@mapbox/node-pre-gyp/lib/util/nw-pre-gyp/index.html 1:0
Module parse failed: Unexpected token (1:0)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
> <!doctype html>
| <html>
| <head>
@ ./node_modules/@mapbox/node-pre-gyp/lib/ sync ^\.\/.*$ ./util/nw-pre-gyp/index.html
@ ./node_modules/@mapbox/node-pre-gyp/lib/node-pre-gyp.js 86:13-36 291:36-53
@ ./node_modules/sqlite3/lib/sqlite3-binding.js 1:15-46
@ ./node_modules/sqlite3/lib/sqlite3.js 2:16-47
@ ./electron/main/db/createDB.ts 2:16-42
@ ./electron/main/main.ts
ERROR in ./node_modules/@mapbox/node-pre-gyp/lib/util/s3_setup.js 43:20-42
Module not found: Error: Can't resolve 'mock-aws-s3' in '/Users/songjunwei/Documents/newmine/viefong-pc/node_modules/@mapbox/node-pre-gyp/lib/util'
@ ./node_modules/@mapbox/node-pre-gyp/lib/node-pre-gyp.js 15:21-62
@ ./node_modules/sqlite3/lib/sqlite3-binding.js 1:15-46
@ ./node_modules/sqlite3/lib/sqlite3.js 2:16-47
@ ./electron/main/db/createDB.ts 2:16-42
@ ./electron/main/main.ts
ERROR in ./node_modules/@mapbox/node-pre-gyp/lib/util/s3_setup.js 76:14-32
Module not found: Error: Can't resolve 'aws-sdk' in '/Users/songjunwei/Documents/newmine/viefong-pc/node_modules/@mapbox/node-pre-gyp/lib/util'
@ ./node_modules/@mapbox/node-pre-gyp/lib/node-pre-gyp.js 15:21-62
@ ./node_modules/sqlite3/lib/sqlite3-binding.js 1:15-46
@ ./node_modules/sqlite3/lib/sqlite3.js 2:16-47
@ ./electron/main/db/createDB.ts 2:16-42
@ ./electron/main/main.ts
ERROR in ./node_modules/@mapbox/node-pre-gyp/lib/util/s3_setup.js 112:15-30
Module not found: Error: Can't resolve 'nock' in '/Users/songjunwei/Documents/newmine/viefong-pc/node_modules/@mapbox/node-pre-gyp/lib/util'
@ ./node_modules/@mapbox/node-pre-gyp/lib/node-pre-gyp.js 15:21-62
@ ./node_modules/sqlite3/lib/sqlite3-binding.js 1:15-46
@ ./node_modules/sqlite3/lib/sqlite3.js 2:16-47
@ ./electron/main/db/createDB.ts 2:16-42
@ ./electron/main/main.ts
ERROR in ./node_modules/node-gyp/lib/Find-VisualStudio.cs 9:6
Module parse failed: Unexpected token (9:6)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
| // This script needs to be compatible with PowerShell v2 to run on Windows 2008R2 and Windows 7.
|
> using System;
| using System.Text;
| using System.Runtime.InteropServices;
@ ./node_modules/node-gyp/lib/ sync ^\.\/.*$ ./Find-VisualStudio.cs
@ ./node_modules/node-gyp/lib/node-gyp.js 41:13-36 195:36-53
@ ./node_modules/@mapbox/node-pre-gyp/lib/util/compile.js 31:26-53
@ ./node_modules/@mapbox/node-pre-gyp/lib/ sync ^\.\/.*$ ./util/compile.js ./util/compile
@ ./node_modules/@mapbox/node-pre-gyp/lib/node-pre-gyp.js 86:13-36 291:36-53
@ ./node_modules/sqlite3/lib/sqlite3-binding.js 1:15-46
@ ./node_modules/sqlite3/lib/sqlite3.js 2:16-47
@ ./electron/main/db/createDB.ts 2:16-42
解决:
安装:
yarn add -D webpack-node-externals
引入webpack中:
const nodeExternals = require('webpack-node-externals');
重点两行:
externalsPresets: { node: true }, // in order to ignore built-in modules like path, fs, etc.
externals: [ 'nock', 'mock-aws-s3', 'aws-sdk', nodeExternals()],
**
**
以上参考:
https://juejin.cn/post/6844904104980905998
https://www.npmjs.com/package/webpack-node-externals
分界线------------------------------------------------
这样是可以解决我昨天打包时报错的问题,但打包后再打开安装包会一直报各种我在electron中所引入的依赖文件,一直解决一直报错,我有感觉就是这个插件所引起的问题:所以我就去看webpack-node-externals这个插件的究竟要解决的问题和我目前所引起的问题究竟是什么?
我已经解决了这个问题,所以我用了别人的一张图
我后来将webpack-node-externals这个插件去掉,然后安装
node-pre-gyp github
npm install @mapbox/node-pre-gyp --save
// 注:我这里的系统已经配置了python等等环境,项目也安装了electron-rebuild包,所以我这里只需要执行下:
./node_modules/.bin/electron-rebuild
参考:https://newsn.net/say/electron-sqlite3.html