NodeJS - 在child_process中找不到模块

时间:2018-04-20 14:04:14

标签: node.js child-process

我想使用child_process在后台执行长任务,而不会降低整个应用程序的速度。

我在child_process中需要sqlite3模块时遇到问题。 这是我的代码:

main.js

const child_process = require('child_process');
const fork = child_process.fork('child.js');

child.js

const sqlite3 = require('sqlite3').verbose();
const db = new sqlite3.Database('data.db');

这是我得到的:

module.js:487     扔错了;     ^

Error: Cannot find module 'A:\myretail\clictill_electron\node_modules\sqlite3\lib\binding\node-v57-win32-x64\node_sqlite3.node'
    at Function.Module._resolveFilename (module.js:485:15)
    at Function.Module._load (module.js:437:25)
    at Module.require (module.js:513:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (A:\myretail\clictill_electron\node_modules\sqlite3\lib\sqlite3.js:4:15)
    at Object.<anonymous> (A:\myretail\clictill_electron\node_modules\sqlite3\lib\sqlite3.js:190:3)
    at Module._compile (module.js:569:30)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:503:32)
    at tryModuleLoad (module.js:466:12)

的package.json:

{
    "name": "clictill_electron",
    "productName": "Clictill",
    "version": "1.0.0",
    "main": "main.js",
    "dependencies": {
        "child_process": "^1.0.2",
        "electron": "^1.8.4",
        "fibers": "^2.0.2",
        "node-gyp": "^3.6.2",
        "node-pre-gyp": "^0.8.0",
        "request": "^2.85.0",
        "sqlite3": "^3.1.13",
        "sync": "^0.2.5"
    },
    "build": {
        "files": [
            "app/**/*",
            "node_modules/**/*",
            "package.json"
        ]
    },
    "scripts": {
        "preinstall": "npm --add-python-to-path='true' --debug install --global windows-build-tools && npm install --global node-gyp && setx PYTHON \"%USERPROFILE%\\.windows-build-tools\\python27\\python.exe\" && npm config set python PYTHON",
        "postinstall": "node_modules/.bin/electron-rebuild -v 1.8.2 -w sqlite3 -p",
        "start": "electron .",
        "release": "build",
        "rebuild": "electron-rebuild -f -w sqlite3"
    },
    "devDependencies": {
        "electron-builder": "^10.8.1",
        "electron-rebuild": "^1.7.3"
    }
}

知道这是从哪里来的吗?

1 个答案:

答案 0 :(得分:0)

您是否检查过您的路径以查看sqlite3模块是否存在于应有的位置?

否则我会做npm child_process uninstall --save,然后执行npm child_process install --save