../node_modules/@mapbox/node-pre-gyp/lib/util/nw-pre-gyp/index.html
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>

Getting this error after I installed sqlite3 with my nextron app

After this I start getting the following error

ModuleParseError: 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;

After that starts getting this error import error

Error: /home/Ankit/Projects/test/node_modules/electron/dist/resources/electron.asar/package.jsondoes not exist

> 1 | const sqlite3 = require("sqlite3").verbose()
                     ^

Don't know how to encounter this, any help would be better, thankyou in advance...

First error get resolved if I add the following code to my next.config.js file

config.module.rules.push({ test: /.html$/, use: "html-loader", });

I resolved the second error too by adding the following code to next.config.js file

config.module.rules.push({
    test: /\.cs$/,
    use: "raw-loader",
});

Also used electron-builder

Also used a substitute better-sqlite3 but getting error of undefined indexOf on initialization.

I'm using: node v16.20.0 sqlite3 v5.1.6 @mapbox/node-pre-gyp v1.0.10

1

There are 1 best solutions below

0
Criminal_Affair_At_SO On

You are trying to load a binary Node.js addon - node-sqlite3 which depends on @mapbox/node-pre-gyp. Depending on what exactly you are doing, this may be impossible.

First of all, these modules do not work in the browser. In the case of Electron, they will work only in the Node.js process.

However in your particular case you also have webpack - probably as part of next.js. webpack tries to make a bundle out of your node_modules and chokes on the code that finds and loads the shared library.

You will have to manually tell webpack to treat the shared library - usually a file ending in .node - as an external and to leave the require() in your code. Look in the index.js of node-sqlite3. You may have to edit it, so that the path to the .node file is fixed instead of being autodetected - this webpack cannot handle.

Then, if your code is executed in the Node.js environment, it will be able to load the library. If it is loaded in the UI render process, it will fail.

I just did something very similar with next.js this way:

next.config.js:

export default {
  webpack: (config) => {
    config.externals.push('everything-json');
    return config;
  }
};

(I am using my own binary module that also uses @mapbox/node-pre-gyp called everything-json)