TryGhost/node-sqlite3

Module not found: Error: Can't resolve 'node-pre-gyp'

Closed this issue Β· 26 comments

ERROR in sqlite3/lib/sqlite3.js
Module not found: Error: Can't resolve 'node-pre-gyp' in

Can help me!!!

npm install node-pre-gyp

after install this package node-pre-gyp
getting lot of error

WARNING in .//node-pre-gyp/lib/util/compile.js
Module not found: Error: Can't resolve 'npm' in '/home/robert/electron/angular2-electron/node_modules/node-pre-gyp/lib/util'
@ ./
/node-pre-gyp/lib/util/compile.js 39:27-49
@ .//node-pre-gyp/lib ^./.*$
@ ./
/node-pre-gyp/lib/node-pre-gyp.js
@ ./~/sqlite3/lib/sqlite3.js
@ ./src/app/login/login.component.ts
@ ./src/app/app.module.ts
@ ./src/main.ts
@ multi webpack-dev-server/client?http://localhost:4200/ ./src/main.ts

WARNING in .//node-gyp/lib/Find-VS2017.cs
Module parse failed: /home/robert/electron/angular2-electron/node_modules/node-gyp/lib/Find-VS2017.cs Unexpected token (7:6)
You may need an appropriate loader to handle this file type.
| // Usage:
| // powershell -ExecutionPolicy Unrestricted -Version "2.0" -Command "&{Add-Type -Path Find-VS2017.cs; [VisualStudioConfiguration.Main]::Query()}"
| using System;
| using System.Text;
| using System.Runtime.InteropServices;
@ ./
/node-gyp/lib ^./.$
@ .//node-gyp/lib/node-gyp.js
@ ./
/node-pre-gyp/lib/util/compile.js
@ ./~/node-pre-gyp/lib ^./.
$
@ .//node-pre-gyp/lib/node-pre-gyp.js
@ ./
/sqlite3/lib/sqlite3.js
@ ./src/app/login/login.component.ts
@ ./src/app/app.module.ts
@ ./src/main.ts
@ multi webpack-dev-server/client?http://localhost:4200/ ./src/main.ts

WARNING in ./~/sqlite3/lib/sqlite3.js
4:14-35 Critical dependency: the request of a dependency is an expression

WARNING in ./~/node-pre-gyp/lib/pre-binding.js
19:22-48 Critical dependency: the request of a dependency is an expression

WARNING in ./~/node-pre-gyp/lib/util/versioning.js
16:20-67 Critical dependency: the request of a dependency is an expression

ERROR in .//node-pre-gyp/lib/info.js
Module not found: Error: Can't resolve 'aws-sdk' in '/home/robert/electron/angular2-electron/node_modules/node-pre-gyp/lib'
@ ./
/node-pre-gyp/lib/info.js 14:14-32
@ .//node-pre-gyp/lib ^./.*$
@ ./
/node-pre-gyp/lib/node-pre-gyp.js
@ ./~/sqlite3/lib/sqlite3.js
@ ./src/app/login/login.component.ts
@ ./src/app/app.module.ts
@ ./src/main.ts
@ multi webpack-dev-server/client?http://localhost:4200/ ./src/main.ts

ERROR in .//node-pre-gyp/lib/publish.js
Module not found: Error: Can't resolve 'aws-sdk' in '/home/robert/electron/angular2-electron/node_modules/node-pre-gyp/lib'
@ ./
/node-pre-gyp/lib/publish.js 17:14-32
@ .//node-pre-gyp/lib ^./.*$
@ ./
/node-pre-gyp/lib/node-pre-gyp.js
@ ./~/sqlite3/lib/sqlite3.js
@ ./src/app/login/login.component.ts
@ ./src/app/app.module.ts
@ ./src/main.ts
@ multi webpack-dev-server/client?http://localhost:4200/ ./src/main.ts

ERROR in .//node-pre-gyp/lib/unpublish.js
Module not found: Error: Can't resolve 'aws-sdk' in '/home/robert/electron/angular2-electron/node_modules/node-pre-gyp/lib'
@ ./
/node-pre-gyp/lib/unpublish.js 15:14-32
@ .//node-pre-gyp/lib ^./.*$
@ ./
/node-pre-gyp/lib/node-pre-gyp.js
@ ./~/sqlite3/lib/sqlite3.js
@ ./src/app/login/login.component.ts
@ ./src/app/app.module.ts
@ ./src/main.ts
@ multi webpack-dev-server/client?http://localhost:4200/ ./src/main.ts

ERROR in .//node-pre-gyp/lib/testbinary.js
Module not found: Error: Can't resolve 'child_process' in '/home/robert/electron/angular2-electron/node_modules/node-pre-gyp/lib'
@ ./
/node-pre-gyp/lib/testbinary.js 10:9-33
@ .//node-pre-gyp/lib ^./.*$
@ ./
/node-pre-gyp/lib/node-pre-gyp.js
@ ./~/sqlite3/lib/sqlite3.js
@ ./src/app/login/login.component.ts
@ ./src/app/app.module.ts
@ ./src/main.ts
@ multi webpack-dev-server/client?http://localhost:4200/ ./src/main.ts

ERROR in .//node-pre-gyp/lib/util/compile.js
Module not found: Error: Can't resolve 'child_process' in '/home/robert/electron/angular2-electron/node_modules/node-pre-gyp/lib/util'
@ ./
/node-pre-gyp/lib/util/compile.js 9:9-33
@ .//node-pre-gyp/lib ^./.*$
@ ./
/node-pre-gyp/lib/node-pre-gyp.js
@ ./~/sqlite3/lib/sqlite3.js
@ ./src/app/login/login.component.ts
@ ./src/app/app.module.ts
@ ./src/main.ts
@ multi webpack-dev-server/client?http://localhost:4200/ ./src/main.ts

ERROR in .//detect-libc/lib/detect-libc.js
Module not found: Error: Can't resolve 'child_process' in '/home/robert/electron/angular2-electron/node_modules/detect-libc/lib'
@ ./
/detect-libc/lib/detect-libc.js 4:16-40
@ .//node-pre-gyp/lib/util/versioning.js
@ ./
/node-pre-gyp/lib ^./.*$
@ .//node-pre-gyp/lib/node-pre-gyp.js
@ ./
/sqlite3/lib/sqlite3.js
@ ./src/app/login/login.component.ts
@ ./src/app/app.module.ts
@ ./src/main.ts
@ multi webpack-dev-server/client?http://localhost:4200/ ./src/main.ts

ERROR in .//node-gyp/lib/node-gyp.js
Module not found: Error: Can't resolve 'child_process' in '/home/robert/electron/angular2-electron/node_modules/node-gyp/lib'
@ ./
/node-gyp/lib/node-gyp.js 16:20-44
@ .//node-pre-gyp/lib/util/compile.js
@ ./
/node-pre-gyp/lib ^./.*$
@ .//node-pre-gyp/lib/node-pre-gyp.js
@ ./
/sqlite3/lib/sqlite3.js
@ ./src/app/login/login.component.ts
@ ./src/app/app.module.ts
@ ./src/main.ts
@ multi webpack-dev-server/client?http://localhost:4200/ ./src/main.ts

ERROR in .//osenv/osenv.js
Module not found: Error: Can't resolve 'child_process' in '/home/robert/electron/angular2-electron/node_modules/osenv'
@ ./
/osenv/osenv.js 3:11-35
@ .//nopt/lib/nopt.js
@ ./
/node-pre-gyp/lib/node-pre-gyp.js
@ ./~/sqlite3/lib/sqlite3.js
@ ./src/app/login/login.component.ts
@ ./src/app/app.module.ts
@ ./src/main.ts
@ multi webpack-dev-server/client?http://localhost:4200/ ./src/main.ts

ERROR in .//node-gyp/lib/node-gyp.js
Module not found: Error: Can't resolve '../package' in '/home/robert/electron/angular2-electron/node_modules/node-gyp/lib'
@ ./
/node-gyp/lib/node-gyp.js 67:16-37
@ .//node-pre-gyp/lib/util/compile.js
@ ./
/node-pre-gyp/lib ^./.*$
@ .//node-pre-gyp/lib/node-pre-gyp.js
@ ./
/sqlite3/lib/sqlite3.js
@ ./src/app/login/login.component.ts
@ ./src/app/app.module.ts
@ ./src/main.ts
@ multi webpack-dev-server/client?http://localhost:4200/ ./src/main.ts

ERROR in .//node-gyp/lib/build.js
Module not found: Error: Can't resolve 'child_process' in '/home/robert/electron/angular2-electron/node_modules/node-gyp/lib'
@ ./
/node-gyp/lib/build.js 14:11-35
@ .//node-gyp/lib ^./.*$
@ ./
/node-gyp/lib/node-gyp.js
@ .//node-pre-gyp/lib/util/compile.js
@ ./
/node-pre-gyp/lib ^./.*$
@ .//node-pre-gyp/lib/node-pre-gyp.js
@ ./
/sqlite3/lib/sqlite3.js
@ ./src/app/login/login.component.ts
@ ./src/app/app.module.ts
@ ./src/main.ts
@ multi webpack-dev-server/client?http://localhost:4200/ ./src/main.ts

ERROR in .//node-gyp/lib/configure.js
Module not found: Error: Can't resolve 'child_process' in '/home/robert/electron/angular2-electron/node_modules/node-gyp/lib'
@ ./
/node-gyp/lib/configure.js 19:9-33
@ .//node-gyp/lib ^./.*$
@ ./
/node-gyp/lib/node-gyp.js
@ .//node-pre-gyp/lib/util/compile.js
@ ./
/node-pre-gyp/lib ^./.*$
@ .//node-pre-gyp/lib/node-pre-gyp.js
@ ./
/sqlite3/lib/sqlite3.js
@ ./src/app/login/login.component.ts
@ ./src/app/app.module.ts
@ ./src/main.ts
@ multi webpack-dev-server/client?http://localhost:4200/ ./src/main.ts

ERROR in .//node-gyp/lib/find-vs2017.js
Module not found: Error: Can't resolve 'child_process' in '/home/robert/electron/angular2-electron/node_modules/node-gyp/lib'
@ ./
/node-gyp/lib/find-vs2017.js 2:15-39
@ .//node-gyp/lib ^./.*$
@ ./
/node-gyp/lib/node-gyp.js
@ .//node-pre-gyp/lib/util/compile.js
@ ./
/node-pre-gyp/lib ^./.*$
@ .//node-pre-gyp/lib/node-pre-gyp.js
@ ./
/sqlite3/lib/sqlite3.js
@ ./src/app/login/login.component.ts
@ ./src/app/app.module.ts
@ ./src/main.ts
@ multi webpack-dev-server/client?http://localhost:4200/ ./src/main.ts

ERROR in .//uid-number/uid-number.js
Module not found: Error: Can't resolve 'child_process' in '/home/robert/electron/angular2-electron/node_modules/uid-number'
@ ./
/uid-number/uid-number.js 9:20-44
@ .//tar-pack/index.js
@ ./
/node-pre-gyp/lib/package.js
@ .//node-pre-gyp/lib ^./.*$
@ ./
/node-pre-gyp/lib/node-pre-gyp.js
@ ./~/sqlite3/lib/sqlite3.js
@ ./src/app/login/login.component.ts
@ ./src/app/app.module.ts
@ ./src/main.ts
@ multi webpack-dev-server/client?http://localhost:4200/ ./src/main.ts

Do you still have this issue? This seems to be a Node configuration issue. Unless you can show how to reproduce this on a recent Node install, I propose that you close this issue

I have this issue too. @RobertRajcool @wmertens any proposed solutions?

I saw this child_process error elsewhere: it was due to the dev using a module in a webpack build that imported child_process somewhere. Browsers cannot use node APIs, so be careful to not include it anywhere.

I had failed to build sqlite3 for thousand times no matter how, for the aws-sdk relys on child_process so every time you require('sqlite3') on client side it could not be resolved.

Luckily, I found an awesome module can work like a charm on both client or server side - sql.js created by the emscripten's author.

If you are still in troubles with integrating electron and sqlite, you should have a try :)

I have same problem. On Windows. Using electron. Exact error is:

./node_modules/sqlite3/node_modules/node-pre-gyp/lib/info.js
Module not found: Can't resolve 'aws-sdk' in 'C:\Users\alexa\kapla4\node_modules\sqlite3\node_modules\node-pre-gyp\lib'

npm install --global --production windows-build-tools is installed.

child_process is only used node-side in my electron project to start electron after create-react-app has started:

const net = require('net')
const port = process.env.PORT ? process.env.PORT - 100 : 5000

process.env.ELECTRON_START_URL = `http://localhost:${port}`

const client = new net.Socket()

let startedElectron = false
const tryConnection = () =>
  client.connect({ port: port }, () => {
    client.end()
    if (!startedElectron) {
      console.log('starting electron')
      startedElectron = true
      const exec = require('child_process').exec
      exec('yarn run electron')
    }
  })

tryConnection()

client.on('error', error => {
  setTimeout(tryConnection, 1000)
})

The exact same project structure and configuration works flawlessly in another project created yesterday that does not use native modules i.e. sqlite3.

@barbalex I'm getting the exact same error message when trying to use Sequelize (which depends on sqlite3) together with Electron, any clue how to solve this?

@axelkennedal I ended up not using create-react-app but instead electron-react-boilerplate which solves the problem by using another package.json file - somehow...

@barbalex I'm also getting same error message with Sequelize, irritating, i'm not using sqlLite3.

I'm getting this problem with fsevents on a Mac. Cannot find a solution.

@mnmpeterson try deleting node_modules, package-lock.json and/or yarn.lock, and install again

Did that, same problem. This is on an angularjs 1.6 project. On an angular 6.x project sfevents will download and compile what it needs from node-gyp but won’t do the same on my angularjs projects.

For what its worth β€” I've run into the same problem. Deleting node_modules and lock files doesnt help, nor does adding node-pre-gyp globally. I think I too will use the other boilerplate

If you are using electron, I used the package "electron-rebuild" to fix this.
I ran the command "./node_modules/.bin/electron-rebuild -f -w sqlite3"
To use sqlite, use "const sqlite = window.require('sqlite3');"

hi all, I am facing the same issue on Mac. Is anyone able to solve this problem?
I tried almost all solution available. Still no luck.

For what its worth β€” I've run into the same problem. Deleting node_modules and lock files doesnt help, nor does adding node-pre-gyp globally. I think I too will use the other boilerplate

Hey, Were you able to fix this issue after using boilerplate code and SQLite? curious to know :)

This problem bothered me for three days, and now it's finally solved
Reference resources
#1029 (comment)

My solution:

  output: {
    path: config.build.assetsRoot,
    filename: '[name].js',
    publicPath: process.env.NODE_ENV === 'production'
      ? config.build.assetsPublicPath
      : config.dev.assetsPublicPath,
      libraryTarget: 'commonjs2'
  },
  externals: {
      sqlite3: 'sqlite3'
  }

important code
libraryTarget: 'commonjs2'
sqlite3: 'sqlite3'

If you solve this problem because of my solution, please share it with those who need help. And use this link。 :)

This was happening to me because I was pointing to the wrong dependency

in my case, it was bcrypt that was causing the issue

error received when using :
const bcrypt = require('bcrypt')

error fixed when using :
const bcrypt = require('bcryptjs')

xtfer commented

Not sure why this was closed. Issue still exists with node-sqlite3 built from HEAD at April 24th 2020.

Thanks @Jclyoung

const bcrypt = require('bcryptjs')

This was helpful to me

for webpack users trying to bundle sqlite3; there may be a better way to do this, but you can override the new sqlite3-binding.js with resolve and point to a different file.

resolve: {
  alias: {
    [path.join(__dirname, 'node_modules/sqlite3/lib/sqlite3-binding.js')]: path.join(__dirname, 'path/to/local/sqlite3-binding.js')
  }
}

path/to/local/sqlite3-binding.js:

var binding = require('bindings')('node_sqlite3');
module.exports = exports = binding;

this approach requires the bindings package.

npm install bindings --save-dev

note: you will have to copy the node_sqlite3.node file to specified directories

July 2021, still having that issue with webpack + sqlite3 on linux
I managed however to solve it by modifying my webpack config file as that comment suggests
#1029 (comment)

This was happening to me because I was pointing to the wrong dependency

in my case, it was bcrypt that was causing the issue

error received when using : const bcrypt = require('bcrypt')

error fixed when using : const bcrypt = require('bcryptjs')

Anyone who decides to try @Jclyoung's recommendation above, I would suggest considering whether you really want to include bcryptjs in your project - seems like an unmaintained library (GitHub) with the last publish in 2017.