Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sqlite3, electron, webpack: cannot find module abi_crosswalk.json

I'm trying to make sqlite3 work in electron in combination with webpack, babel and react.

These are the dependencies in package.json:

"devDependencies": {
    "babel-core": "^6.7.0",
    "babel-loader": "^6.2.4",
    "babel-preset-es2015": "^6.6.0",
    "babel-preset-react": "^6.5.0",
    "css-loader": "^0.23.1",
    "electron-packager": "^5.2.1",
    "electron-prebuilt": "^0.36.8",
    "electron-rebuild": "^1.1.3",
    "node-sass": "^3.4.2",
    "react": "^0.14.7",
    "react-dom": "^0.14.7",
    "sass-loader": "^3.1.2",
    "style-loader": "^0.13.0",
    "webpack": "^1.12.14",
    "webpack-dev-server": "1.14.0"
  },
  "dependencies": {
      "sqlite3": "^3.1.1"
  }

After running npm install, I ran ./node_modules/.bin/electron-rebuild as described in the documentation.

This is my webpack.config.js:

var webpack = require('webpack');
module.exports = {
    context: __dirname + '/src',
    entry: './entry.js',
    target: 'electron',

    output: {
        filename: 'bundle.js',
        path: __dirname + '/build',
        publicPath: 'http://localhost:8080/build/'
    },

    module: {
        loaders: [{
            test: /\.js$/,
            loader: 'babel',
            exclude: /node_modules/,
            query: {
                presets: ['es2015', 'react']
            }
        }, {
            test: /\.scss$/,
            loader: 'style-loader!css-loader!sass-loader'
        }]
    }
};

When I add var sqlite3 = require('sqlite3').verbose(); to my code and try to run this, I'll get the following error messages:

`Uncaught Error: Cannot find module "./abi_crosswalk.json"`

./~/sqlite3/~/node-pre-gyp/package.json
Module parse failed: .../node_modules/sqlite3/node_modules/node-pre-gyp/package.json Line 2: Unexpected token :
You may need an appropriate loader to handle this file type.
| {
|   "name": "node-pre-gyp",
|   "description": "Node.js native addon binary install tool",
|   "version": "0.6.14",
 @ ./~/sqlite3/~/node-pre-gyp/lib/node-pre-gyp.js 60:16-37

And in consequence, a bunch of modules can't be found.

Can anyone help me with this?

Edit: This is the code in bundle.js that results in the package.json error mentioned in the comments.

function(module, exports, __webpack_require__) {

    "use strict";

    var versioning = __webpack_require__(310);
    var existsSync = __webpack_require__(19).existsSync || __webpack_require__(273).existsSync;
    var path = __webpack_require__(273);

    module.exports = exports;

    exports.usage = 'Finds the require path for the node-pre-gyp installed module';

    exports.validate = function(package_json) {
        versioning.validate_config(package_json);
    };

    exports.find = function(package_json_path,opts) {
       if (!existsSync(package_json_path)) {
            throw new Error("package.json does not exist at " + package_json_path);
       }
       var package_json = __webpack_require__(1133)(package_json_path);
       versioning.validate_config(package_json);
       opts = opts || {};
       if (!opts.module_root) opts.module_root = path.dirname(package_json_path);
       var meta = versioning.evaluate(package_json,opts);
       return meta.module;
    };


/***/ },

1 Answers

It seems like var sqlite3 = require('sqlite3').verbose(); only works in the main process, but not in any render processes. Problem solved.


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!