Sqlite3,电子,webpack:找不到模块abi_crosswalk.json

时间:2016-03-10 11:35:49

标签: node.js sqlite webpack electron

我试图让sqlite3与webpack,babel一起在电子中工作并做出反应。

这些是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"
  }

运行npm install后,我按照documentation中的说明运行./node_modules/.bin/electron-rebuild

这是我的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'
        }]
    }
};

当我将var sqlite3 = require('sqlite3').verbose();添加到我的代码并尝试运行时,我会收到以下错误消息:

`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

因此,无法找到一堆模块。

任何人都可以帮我吗?

编辑:这是bundle.js中的代码,导致注释中提到的package.json错误。

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;
    };


/***/ },

2 个答案:

答案 0 :(得分:3)

似乎class AuthorizationInterceptor implements Interceptor { @Override public Response intercept(Chain chain) throws IOException { Request originalRequest = chain.request(); String authorizationToken = AuthenticationUtils.getToken(); Request authorizedRequest = originalRequest.newBuilder() .header("Authorization", authorizationToken) .build(); return chain.proceed(authorizedRequest); } } 仅适用于主进程,但不适用于任何渲染进程。问题解决了。

答案 1 :(得分:0)

安装npm后,试试这个:./ node_modules / .bin / electronon-renbuild -w sqlite3 -p。 首先,您应该安装sqlite3和electron-rebuild。