4
votes

I want to use Webpack on my projects, but when I run

npm run dev

, I get this error.

ERROR in ./~/sqlite3/~/node-pre-gyp/lib/node-pre-gyp.js Module not found: Error: Cannot resolve 'file' or 'directory' ../package in /Users/caizongming/Flowerhop/-DBLab-Alarm-Project-/Server/node_modules/sqlite3/node_modules/node-pre-gyp/lib @ ./~/sqlite3/~/node-pre-gyp/lib/node-pre-gyp.js 60:16-37

ERROR in ./~/sqlite3/~/node-pre-gyp/lib/info.js Module not found: Error: Cannot resolve module 'aws-sdk' in /Users/caizongming/Flowerhop/-DBLab-Alarm-Project-/Server/node_modules/sqlite3/node_modules/node-pre-gyp/lib @ ./~/sqlite3/~/node-pre-gyp/lib/info.js 14:14-32

ERROR in ./~/sqlite3/~/node-pre-gyp/lib/publish.js Module not found: Error: Cannot resolve module 'aws-sdk' in /Users/caizongming/Flowerhop/-DBLab-Alarm-Project-/Server/node_modules/sqlite3/node_modules/node-pre-gyp/lib @ ./~/sqlite3/~/node-pre-gyp/lib/publish.js 17:14-32

ERROR in ./~/sqlite3/~/node-pre-gyp/lib/unpublish.js Module not found: Error: Cannot resolve module 'aws-sdk' in /Users/caizongming/Flowerhop/-DBLab-Alarm-Project-/Server/node_modules/sqlite3/node_modules/node-pre-gyp/lib @ ./~/sqlite3/~/node-pre-gyp/lib/unpublish.js 15:14-32

ERROR in ./~/sqlite3/~/rc/index.js Module build failed: Error: Parse Error: Line 1: Unexpected token 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) at advance (/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

This is my 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'
};

This is 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"
}

Can anybody help me fix this problem?

2
I get similar error when submitting "ionic serve" :-(Kieran Ryan
Did you look into marking them as external? webpack.github.io/docs/library-and-externals.htmlSean Chase
@Flowerhop Were you able to solve this issue?codingninja

2 Answers

1
votes

I encountered the similar problem with the lzma-native, which also uses node-pre-gyp. The problem is they all directly require the node-pre-gyp in the module. I try to replace the line of code that use 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);

into

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

And that finally works for me. Though, this solution requires us to modify the source code, and add an additional dependency 'pre-gyp-find'. Maybe you could send a PR to author about this.

This is not the best solution, since it doesn't actually solve but avoid the problem.

0
votes

I noticed everything seems right during npm install, but actually there is some error during install. My problem was fixed with "npm install sqlite3 --build-from-source"