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

Cannot find module '[...]/node_sqlite3.node' #442

Closed
FrankV01 opened this issue Aug 12, 2017 · 16 comments
Closed

Cannot find module '[...]/node_sqlite3.node' #442

FrankV01 opened this issue Aug 12, 2017 · 16 comments

Comments

@FrankV01
Copy link

Bug Report

Summary

Attempting to ghost install --db=sqlite3 into what I'll call a staging server. It's a fresh install of Ubuntu 16.04 LTS; no domain associated -- I'm using the IP Address as the url. On the server, I've only installed updates, node, and build-essentials on it. Very sparse. (I also updated npm). Towards the end of the install I get the following:

[...]
? Do you wish to set up Systemd? No
ℹ Setting up Systemd [skipped]
Running sudo command: -E -u ghost /usr/lib/node_modules/ghost-cli/node_modules/.bin/knex-migrator-migrate --init --mgpath /home/frank01/beta02/current
Knex: run
$ npm install sqlite3 --save
Error: Cannot find module '/usr/lib/node_modules/ghost-cli/node_modules/sqlite3/lib/binding/node-v48-linux-x64/node_sqlite3.node'
    at Function.Module._resolveFilename (module.js:469:15)
    at Function.Module._load (module.js:417:25)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/usr/lib/node_modules/ghost-cli/node_modules/sqlite3/lib/sqlite3.js:4:15)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at Client_SQLite3._driver (/usr/lib/node_modules/ghost-cli/node_modules/knex/lib/dialects/sqlite3/index.js:75:12)
    at Client_SQLite3.initializeDriver (/usr/lib/node_modules/ghost-cli/node_modules/knex/lib/client.js:219:26)
    at Client_SQLite3.Client (/usr/lib/node_modules/ghost-cli/node_modules/knex/lib/client.js:113:10)
    at new Client_SQLite3 (/usr/lib/node_modules/ghost-cli/node_modules/knex/lib/dialects/sqlite3/index.js:58:20)
    at Knex (/usr/lib/node_modules/ghost-cli/node_modules/knex/lib/index.js:60:34)
    at Object.connect (/usr/lib/node_modules/ghost-cli/node_modules/knex-migrator/lib/database.js:24:12)
    at KnexMigrator.init (/usr/lib/node_modules/ghost-cli/node_modules/knex-migrator/lib/index.js:71:32)
    at KnexMigrator.migrate (/usr/lib/node_modules/ghost-cli/node_modules/knex-migrator/lib/index.js:160:21)
    at /usr/lib/node_modules/ghost-cli/node_modules/knex-migrator/bin/knex-migrator-migrate:26:29
    at tryCatcher (/usr/lib/node_modules/ghost-cli/node_modules/bluebird/js/release/util.js:16:23)
✖ Running database migrations
An error occurred.
Message: 'Command failed: /bin/sh -c sudo -E -u ghost /usr/lib/node_modules/ghost-cli/node_modules/.bin/knex-migrator-migrate --init --mgpath /home/frank01/beta02/current
'


Debug Information:
    Node Version: v6.11.2
    Ghost-CLI Version: 1.0.3
    Environment: production
    Command: 'ghost install --db=sqlite3'

Additional log info available in: /home/frank01/.ghost/logs/ghost-cli-debug-2017-08-12T12_38_04_426Z.log

Steps to Reproduce (for a bug report)

  1. Create Ubuntu 16.04 LTS server (note: I was ssh'd in as a non-root user who has sudo access)
  2. apt update && apt upgrade
  3. install Node via the Nodejs PPA & build-essentials
  4. npm install -g npm && npm install -g ghost-cli
  5. cd ~ && mkdir beta01 && cd beta01
  6. ghost install --db=sqlite3

Technical detail

Debug Information:
    Node Version: v6.11.2
    Ghost-CLI Version: 1.0.3
    Environment: production
    Command: 'ghost install --db=sqlite3'
@ErisDS
Copy link
Member

ErisDS commented Aug 12, 2017

Can you please provide the output of:

  • npm -v
  • npm root -g
  • npm bin -g

I'm not sure what's causing this, but my first guess is the upgrade to npm, as that's the place where your setup deviates from the install guide.

@FrankV01
Copy link
Author

Results of the queries.

Welcome to Ubuntu 16.04.3 LTS (GNU/Linux 4.9.36-x86_64-linode85 x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage
Last login: Sat Aug 12 12:32:44 2017 from [removed]
> npm -v
5.3.0
> npm root -g
/usr/lib/node_modules
> npm bin -g
/usr/bin

@ErisDS
Copy link
Member

ErisDS commented Aug 12, 2017

Nothing obvious there.

What's inside/usr/lib/node_modules/ghost-cli/node_modules/sqlite3/lib/binding?

Only other thing I can think of here is permissions. As you did npm install -g ghost-cli without sudo, it seems you maybe ran it as root? Our install guide recommends creating a non-root user & installing ghost-cli using sudo.

The interactions between your node version, permissions and sqlite bindings are always very fragile. There are some notes in the troubleshooting guide that should shed light on why: https://docs.ghost.org/docs/troubleshooting#section-sqlite3-errors

I'm keen to find out what went wrong here so we can detect it with ghost cli in future.

@acburdine
Copy link
Member

FWIW - when I've done Ubuntu testing before I was never able to get sqlite3 to properly install with Ghost-CLI and npm 5. I always had to install Python first. Npm3 never gave me any issues.

Not sure what changed but it's likely something with node-gyp or how npm5 runs scripts differently than npm3.

@FrankV01
Copy link
Author

The binding folder doesn't exist. I've listed the contents of the folder prior below along with their owner. Indeed, I did originally install ghost-cli as root but had re-tried to install it on the sudo user. however, without sudo, no global node modules will install.

I'm assuming my installation of node (globally) is bad or somehow incorrect? That I should be able to install npm packages globally without sudo...

frank01@Dev-tOSU-01[/usr/lib/node_modules/ghost-cli/node_modules/sqlite3/lib] ls -al
total 24
drwxr-xr-x 2 root root 4096 Aug 11 01:40 .
drwxr-xr-x 8 root root 4096 Aug 11 01:41 ..
-rw-r--r-- 1 root root   39 Feb 12  2014 index.js
-rw-r--r-- 1 root root 5554 Oct 27  2016 sqlite3.js
-rw-r--r-- 1 root root 1437 Oct 27  2016 trace.js

@FrankV01
Copy link
Author

FrankV01 commented Aug 12, 2017

@ErisDS I've fixed it on my system. It was a permissions issue or at least that is what solved it.

What I did -- and I have no idea if this is proper -- is change the permissions recursively on the /usr/lib/node_modules folder. I gave the whole directory tree read/write/execute... After this, I removed the ghost cli with npm uninstall and reinstalled it without sudo. I then ran the basic ghost install --db=sqlite3 and it seemed to work as documented.

Despite my issue being solved, I suspect you want to address this situation in the cli (based on above conversation) and thus I'll leave it open. I'll provide any further information requested that I can.

Thank you for help on this.

Update: For those who run in to this issue and are try to correctly fix it, please use the instructions provided here: https://docs.npmjs.com/getting-started/fixing-npm-permissions -- this is the correct way to fix this.

@ddhp
Copy link

ddhp commented Sep 10, 2017

I bumped into this issue as well since I start using ghost-cli migrating from ghost v0.7
Thanks @FrankV01 for all the information but I found out it's not related to permission

I followed the solution you gave, and here is the result:

> npm root -g
~/.npm-global/lib/node_modules

and I have checked all permission is set properly, but error was still there

so later I tried cd ~/.npm-global/lib/node_modules/ghost-cli and run npm install sqlite3
then it's solved

so I think the root cause is ghost cli won't install sqlite3 globally even if --db sqlite3 parameter is given

sorry I haven't had time to check source code, so FYI @ErisDS, also thanks for all the awesome works

@remingtonc
Copy link

remingtonc commented Oct 13, 2017

@ddhp I love you.
cd `npm root -g`/ghost-cli && [sudo] npm install sqlite3
Been trying every other fix under the sun for hours.

@acburdine
Copy link
Member

Gonna close this for now as it should have been fixed by #505. If you run into the same issue with Ghost-CLI 1.3.0 - comment and we can reopen this :)

@PothuluruMahesh
Copy link

Knex: run
$ npm install sqlite3 --save
Error: Cannot find module 'F:\UpdateALT5\althingscustomerapp\AlThingsCustomer\node_modules\sqlite3\lib\binding\electron-v2.0-win32-x64\node_sqlite3.node'

@truekasun
Copy link

I'm having the same issue on

Debug Information:
Node Version: v14.15.1
Ghost-CLI Version: 1.15.2
Environment: development
Command: 'ghost install local'
Platform: mac

@quintenrosseel
Copy link

I have the same issue on a fresh install.

Debug Information:
Node Version: v14.15.3
Ghost-CLI Version: 1.15.3
Environment: development
Command: 'ghost install local'
Platform: MacOS Big Sur 11.01

@quintenrosseel
Copy link

I have the same issue on a fresh install.

Debug Information:
Node Version: v14.15.3
Ghost-CLI Version: 1.15.3
Environment: development
Command: 'ghost install local'
Platform: MacOS Big Sur 11.01

I was able to resolve the issue by re-installing the xcode command line tools and running:
ghost update --force in the root directory of the ghost CMS app as the stack trace suggested:

No receipt for 'com.apple.pkg.CLTools_Executables' found at '/'. No receipt for 'com.apple.pkg.DeveloperToolsCLILeo' found at '/'. No receipt for 'com.apple.pkg.DeveloperToolsCLI' found at '/'. gyp: No Xcode or CLT version detected!

This post was helpful to reinstall xcode dev tools.

@picardplaisimond
Copy link

I have the same issue, but on windows.

@joanrieu
Copy link

joanrieu commented Jan 9, 2021

I had this problem on Windows as well, but I noticed that I couldn't install sqlite3 from NPM at all because it couldn't find a precompiled binary so it tried building with node-gyp which needs Python which wasn't installed on my system.

Installing Python solved the issue, ghost install local works fine now.

The Ghost CLI is hiding node-gyp's Python-related error messages for some reason.

@acburdine
Copy link
Member

acburdine commented Jan 10, 2021

The Ghost CLI is hiding node-gyp's Python-related error messages for some reason.

@joanrieu I think those logs should be available in the file noted in the error output as "Additional log info available in <filename>" - we should be saving Yarn's stderr and outputting it there. If not I can look at fixing it and/or improving the normal messaging output to include the node-gyp errors.

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

No branches or pull requests

10 participants