Webpack:ERROR in ./~/sqlite3/~/node-pre-gyp/lib/node-pre-gyp.js找不到模块:错误:无法解析' file'或者'目录' ../包

时间:2016-06-01 03:56:21

标签: javascript node.js sqlite webpack

我想在我的项目中使用Webpack,但是当我运行

npm run dev

,我收到了这个错误。

  错误在./~/sqlite3/~/node-pre-gyp/lib/node-pre-gyp.js模块没有   发现:错误:无法解析'文件'或者'目录' ../package in   /用户/ caizongming / Flowerhop / -DBLab-报警-项目 - /服务器/ node_modules / sqlite3的/ node_modules /节点预GYP / lib中   @ ./~/sqlite3/~/node-pre-gyp/lib/node-pre-gyp.js 60:16-37

      ./~/sqlite3/~/node-pre-gyp/lib/info.js中的错误找不到模块:   错误:无法解析模块' aws-sdk'在   /用户/ caizongming / Flowerhop / -DBLab-报警-项目 - /服务器/ node_modules / sqlite3的/ node_modules /节点预GYP / lib中   @ ./~/sqlite3/~/node-pre-gyp/lib/info.js 14:14-32

     错误在./~/sqlite3/~/node-pre-gyp/lib/publish.js找不到模块:   错误:无法解析模块' aws-sdk'在   /用户/ caizongming / Flowerhop / -DBLab-报警-项目 - /服务器/ node_modules / sqlite3的/ node_modules /节点预GYP / lib中   @ ./~/sqlite3/~/node-pre-gyp/lib/publish.js 17:14-32

     错误在./~/sqlite3/~/node-pre-gyp/lib/unpublish.js找不到模块:   错误:无法解析模块' aws-sdk'在   /用户/ caizongming / Flowerhop / -DBLab-报警-项目 - /服务器/ node_modules / sqlite3的/ node_modules /节点预GYP / lib中   @ ./~/sqlite3/~/node-pre-gyp/lib/unpublish.js 15:14-32

      ./~/sqlite3/~/rc/index.js中的错误模块构建失败:错误:解析   错误:第1行:意外的令牌ILLEGAL       at throwError(/Users/caizongming/Flowerhop/-DBLab-Alarm-Project-/Server/node_modules/jsx-loader/node_modules/jstransform/node_modules/esprima-fb/esprima.js:2823:21)       at scanPunctuator(/Users/caizongming/Flowerhop/-DBLab-Alarm-Project-/Server/node_modules/jsx-loader/node_modules/jstransform/node_modules/esprima-fb/esprima.js:1011:9)       提前(/Users/caizongming/Flowerhop/-DBLab-Alarm-Project-/Server/node_modules/jsx-loader/node_modules/jstransform/node_modules/esprima-fb/esprima.js:1747:16)       at peek(/Users/caizongming/Flowerhop/-DBLab-Alarm-Project-/Server/node_modules/jsx-loader/node_modules/jstransform/node_modules/esprima-fb/esprima.js:1773:21)       at parseProgram(/Users/caizongming/Flowerhop/-DBLab-Alarm-Project-/Server/node_modules/jsx-loader/node_modules/jstransform/node_modules/esprima-fb/esprima.js:6535:9)       at Object.parse(/Users/caizongming/Flowerhop/-DBLab-Alarm-Project-/Server/node_modules/jsx-loader/node_modules/jstransform/node_modules/esprima-fb/esprima.js:7713:23)       at getAstForSource(/Users/caizongming/Flowerhop/-DBLab-Alarm-Project-/Server/node_modules/jsx-loader/node_modules/jstransform/src/jstransform.js:244:21)       at Object.transform(/Users/caizongming/Flowerhop/-DBLab-Alarm-Project-/Server/node_modules/jsx-loader/node_modules/jstransform/src/jstransform.js:267:11)       at Object.transform(/Users/caizongming/Flowerhop/-DBLab-Alarm-Project-/Server/node_modules/jsx-loader/node_modules/jstransform/src/simple.js:105:28)       at Object.module.exports(/Users/caizongming/Flowerhop/-DBLab-Alarm-Project-/Server/node_modules/jsx-loader/index.js:15:31)   @ ./~/sqlite3/~/node-pre-gyp/lib/info.js 11:13-26

这是我的WEBPACK.CONFIG.js

var path = require ('path');

module.exports = {
  entry: './server.js',
  output: {
    filename: 'bundle.js'
  },
  module: {
    loaders:[
      { test: /\.css$/, loader: "style!css" },
      { test: /\.js$/, loader: 'jsx-loader?harmony' },
      { test: /\.json$/, loader: 'json-loader' }
    ]
  },
  resolve: {
    fallback: path.join(__dirname, "node_modules"),
    extensions : ['', '.js', '.jsx']
  },
  resolveLoader: { fallback: path.join(__dirname, "node_modules") },
  target: 'node'
};

这是package.json。

{
  "name": "biocenter",
  "version": "1.0.0",
  "description": "",
  "main": "server.js",
  "directories": {
    "test": "test"
  },
  "dependencies": {
    "body-parser": "^1.15.0",
    "express": "^4.13.4",
    "request": "^2.72.0",
    "sqlite3": "^3.1.4",
    "querystring": "^0.2.0",
    "should": "^8.3.2"
  },
  "devDependencies": {
    "brfs": "^1.4.3",
    "json-loader": "^0.5.4",
    "mocha": "^2.4.5",
    "transform-loader": "^0.2.3",
    "webpack": "^1.13.1"
  },
  "scripts": {
    "test": "mocha",
    "start": "node server.js",
    "dev": "webpack-dev-server --devtool eval --progress --colors",
    "deploy": "NODE_ENV=production webpack -p"
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/FlowerHop/-DBLab-Alarm-Project-.git"
  },
  "author": "Flowerhop",
  "license": "ISC",
  "bugs": {
    "url": "https://github.com/FlowerHop/-DBLab-Alarm-Project-/issues"
  },
  "homepage": "https://github.com/FlowerHop/-DBLab-Alarm-Project-#readme"
}

有人可以帮我解决这个问题吗?

2 个答案:

答案 0 :(得分:1)

我遇到了与lzma-native类似的问题,它也使用了node-pre-gyp。问题是它们都直接需要模块中的节点pre-gyp。我尝试替换使用node-pre-gyp

的代码行
var nodePreGyp = require('node-pre-gyp');
var path = require('path');
var binding_path = nodePreGyp.find(path.resolve(path.join(__dirname,'./package.json')));
var native = require(binding_path);

进入

var native = require('pre-gyp-find')('lzma_native');
// notice that the parameter here is the binary module name in package.json of lzma-native

这最终对我有用。但是,此解决方案要求我们修改源代码,并添加额外的依赖性' pre-gyp-find'。也许你可以向作者发送关于此的PR。

这不是最好的解决方案,因为它实际上并没有解决,而是避免了这个问题。

答案 1 :(得分:0)

我注意到在npm安装期间一切正常,但实际上在安装过程中出现了一些错误。我的问题已通过“npm install sqlite3 --build-from-source”

修复