Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
RobertRajcool opened this issue Nov 15, 2017 · 26 comments · Fixed by #1268
Closed

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

RobertRajcool opened this issue Nov 15, 2017 · 26 comments · Fixed by #1268

Comments

@RobertRajcool
Copy link

RobertRajcool commented Nov 15, 2017

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

@RobertRajcool
Copy link
Author

Can help me!!!

@benschool
Copy link

npm install node-pre-gyp

@RobertRajcool
Copy link
Author

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

@wmertens
Copy link
Contributor

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

@gitsana
Copy link

gitsana commented Jan 26, 2018

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

@wmertens
Copy link
Contributor

wmertens commented Jan 29, 2018 via email

@wmertens
Copy link
Contributor

wmertens commented Feb 1, 2018

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.

@marswong
Copy link

marswong commented Feb 3, 2018

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 :)

@wmertens
Copy link
Contributor

wmertens commented Feb 3, 2018 via email

@barbalex
Copy link

barbalex commented Apr 4, 2018

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.

@axelkennedal
Copy link

@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?

@barbalex
Copy link

barbalex commented Oct 9, 2018

@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...

@dstrawsb
Copy link

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

@mnmpeterson
Copy link

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

@wmertens
Copy link
Contributor

wmertens commented Feb 2, 2019

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

@mnmpeterson
Copy link

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.

@askogrand
Copy link

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

@WilliamC07
Copy link

WilliamC07 commented Aug 11, 2019

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');"

@mayurssoni2456
Copy link

mayurssoni2456 commented Oct 9, 2019

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 :)

@feng005211
Copy link

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。 :)

@Jclyoung
Copy 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
Copy link

xtfer commented Apr 23, 2020

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

@rajtrydot
Copy link

rajtrydot commented Sep 13, 2020

Thanks @Jclyoung

const bcrypt = require('bcryptjs')

This was helpful to me

@firien
Copy link

firien commented Nov 23, 2020

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

@dotgreg
Copy link

dotgreg commented Jul 15, 2021

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)

@karlhorky
Copy link

karlhorky commented Feb 27, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.