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

Electron + Webpack + React: SQLite package has not been found installed #2456

Closed
rohmanhm opened this issue Jul 3, 2018 · 14 comments
Closed

Comments

@rohmanhm
Copy link
Contributor

rohmanhm commented Jul 3, 2018

Issue type:

[x] question
[ ] bug report
[ ] feature request
[ ] documentation issue

Database system/driver:

[ ] cordova
[ ] mongodb
[ ] mssql
[ ] mysql / mariadb
[ ] oracle
[ ] postgres
[x] sqlite
[ ] sqljs
[ ] react-native

TypeORM version:

[x] latest
[ ] @next
[ ] 0.x.x (or put your version here)

Steps to reproduce or a small repository showing the problem:

I using this boilerplate to make my electron app. https://github.com/iRath96/electron-react-typescript-boilerplate

I follow the same instruction as https://github.com/typeorm/electron-typescript-example did, but when I run yarn dev on my project it throws an error like below on console developer tools electron app.

Error:  Error: SQLite package has not been found installed. Try to install it: npm install sqlite3 --save
    at new DriverPackageNotInstalledError 

image

I have removed and reinstall node_modules but it didn't work.
I also double check if sqlite3 present on node_modules or not. But it's available.

image

So I've made repository if you want to check it out, here is my repo https://github.com/rohmanhm/ts-electron-react-typeorm-sqlite

Any way to solve this issue? Any suggestion will be helpful.

@HyperSprite
Copy link

This my help, maybe it won't...
I am using electron-react-boilerplate (no typescript) and using TypeORM from main with ipc coms from render with SQLite (I was using SQL.js but TypeORM seems does not expect that in node, that worked in dev but I could never get it to build in prod no matter how I installed things). Also, not using decorators so I feel like I'm doing everything the hard way.
In order for it to work correctly for hot Dev and Prod build, I had to

  • Install SQLite and TypeORM in the app/package.json, even though TypeORM is not native.
  • Do a rebuild after the install of SQLite, even though it was supposed to do that automatically.
  • Move my entity folder and ormconfig into app/
  • Import the ormconfig file directly to the createConnection().

I may be doing this all wrong but TypeORM seems to make assumptions about where things are supposed to be installed (near the package.json file, lol) and this was the only way I could get it to work.
Here is my working repo: https://github.com/HyperSprite/electron-react-boilerplate-with-material-ui

@rohmanhm
Copy link
Contributor Author

rohmanhm commented Jul 3, 2018

Thanks for your solution @HyperSprite, maybe that's a little complicated.
I'll take a look your repo.

I'm still waiting for @pleerock , maybe he has a better solution for this issue.

@pleerock
Copy link
Member

pleerock commented Jul 3, 2018

I also double check if sqlite3 present on node_modules or not. But it's available.

There is a catch block that catches error and gives you another error. Try to console.log original error in the SqliteDriver source code and see what exactly error you have.

I follow the same instruction as https://github.com/typeorm/electron-typescript-example did,

make sure to do exact instructions, also use npm instead of yarn just to be sure that its not related to yarn somehow.

Usually problem can be with native module built by sqlite make sure its there (post-install script does it) and its built for electron.

@rohmanhm
Copy link
Contributor Author

rohmanhm commented Jul 4, 2018

I removed and reinstall all the packages using npm install and run the command using npm, But the result still the same.

This is what error I've got after console.log from SqliteDriver source code.

Cannot find module 'C:\Users\Romsy\Documents\Code\Projects\savings\node_modules\sqlite3\lib\binding\electron-v1.8-win32-x64\node_sqlite3.node'
    at Module._resolveFilename 

I think it's related to electron/electron#10220

@rohmanhm
Copy link
Contributor Author

rohmanhm commented Jul 4, 2018

I finally fixed my issue by installing this package https://github.com/electron/electron-rebuild, and run

electron-rebuild -f -w sqlite3

Thanks, everyone 🙂

@rohmanhm rohmanhm closed this as completed Jul 4, 2018
@rohmanhm
Copy link
Contributor Author

rohmanhm commented Jul 4, 2018

Maybe this one needs to be added to the docs since a lot of windows users like me getting the same issue.

@pleerock
Copy link
Member

pleerock commented Jul 6, 2018

there is actually a post-install script in package.json that runs electron-rebuild for you

@dbishoponline
Copy link

I have same issue. I have tried using electron-rebuild, but no luck.

@HyperSprite
Copy link

I know this is old and closed but just want to add a note about my final solution with Electron. Not sure it will work in this case but thought I'd add this anyway.

The real problem for me was the Electron React Boilerplate (ERB) was using a 2 package.json file system and even though I was able to get things to work initially, it was whack-a-mole with other issues. I ended up collapsing ERB into a single package.json repo (I filed a PR back to ERB last year, it might finally be in their .next branch now, not sure, my project is no longer tracking to that). The single package.json system makes the electron-builder work as expected without any extra config or messing around.

@jjhbw
Copy link
Contributor

jjhbw commented Dec 7, 2019

I ran into the same problem (Electron + Create React App / Webpack).
For me the only solution ended up being #4210 (comment)

@ItsMeSousuke
Copy link

It's working on 0.2.13, on newer version it's not working and show error like in issue. Try to downgrade typeorm dependency to this version.

@darekf77
Copy link

For my the fix was to change install script from:

npm install --ignore-scripts

to

npm install

@oktapodia
Copy link

Just a follow up for recent versions.

add sqlite3 to the dependencies of the release/app/package.json file

pass manually the driver (typeorm is doing a relative path resolution)

import sqlite3 from 'sqlite3';
    const dataSource = new DataSource({
      type: "sqlite",
      database: "database.sqlite",
      driver: sqlite3, // The important line
      synchronize: true,
      logging: true,
      entities: [User],
      migrations: [],
      subscribers: [],
    })

No errors anymore

@vijaysharma0757
Copy link

I have also faced same issue. Resolved by several steps.
Steps

  1. Add sqlite and typeorm in release/app/package.json file. Please install only version for sqlite@5.1.6
    npm install sqlite3@5.1.6 --save
    npm install typeorm --save
  2. Remove sqlite and typeorm from dependencies in package.json file and add to devDependencies
    npm install sqlite3@5.1.6 --save-dev
    npm install typeorm --save-dev

Below error resolved by changing sqlite version 5.1.6
Screenshot 2024-04-09 at 5 29 48 PM

Below error resolved by step 2. if we add sqlite and typeorm in devDependencies
Screenshot 2024-04-09 at 5 28 44 PM

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

9 participants