A way to solve error in packing electron app with sqlite3
侧边栏壁纸
  • 累计撰写 17 篇文章
  • 累计收到 22 条评论

A way to solve error in packing electron app with sqlite3

拾雨
2023-11-01 / 0 评论 / 209 阅读 / 正在检测是否收录...
温馨提示:
本文最后更新于2023年11月01日,已超过543天没有更新,若内容或图片失效,请留言反馈。
你现在看到的是本文章的英文版本,中文版本请前往 Electron应用打包Sqlite3报错的解决方案

Recently I build a Electron program with database.
I finally chose the Sqlite3 module to connect with my database. It worked well in dev mode. When I prepared to pack and publich it throwed the error below:

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>

after installing pnpm i npm bluebird mock-aws-s3 aws-sdk nock --save-optional

and aws-sdkmock-aws-s3nock were not found
a script .cs could not run(not C#, a powershell script)

Ways to solve

For the first issue, it showes that HTML's loader was not found when webpack tried to pack program. So you should edit the config of webpack. Add the rules in the config's module->rules:

      {
        test: /\.html$/,
        use: {
          loader: 'html-loader',
        },
      }

This attach the HTML files with html-loader, which can properly handle the file.

For the next issue, it is also lack of a loader for Sqlite3 to pack. I found for a while and got the solution in a Github issue #1700
Install sqlite3-loadernode-loader

npm install sqlite3-loader node-loader

Samely update the config of webpack:

        {
            test: /sqlite3-binding\.js$/,
            use: [ 'sqlite3-loader' ],
        },

        {
            test: /\.node$/,
            use: 'node-loader',
        },

Repack and success

Tips

When finding the solution, someone said add this to webpack config:

externals: {
      sqlite3: 'sqlite3'
  }

I tried and it could pack, but will exclude the sqlite3 module and when running the packed program it cannot found it. So the program cannot run properly.

0

评论 (0)

取消