I try to add sqlite3 to electron app. I get this errors on compilation:
[2018-08-21 16:52:32.299 - INFO] :shadow.build.npm/js-invalid-requires - {:resource-name "node_modules/sqlite3/lib/sqlite3.js", :requires [{:line 4, :column 14}]}
[2018-08-21 16:52:32.544 - INFO] :shadow.build.npm/js-invalid-requires - {:resource-name "node_modules/node-pre-gyp/lib/node-pre-gyp.js", :requires [{:line 52, :column 13} {:line 184, :column 38}]}
[2018-08-21 16:52:33.958 - INFO] :shadow.build.npm/js-invalid-requires - {:resource-name "node_modules/node-pre-gyp/lib/pre-binding.js", :requires [{:line 20, :column 22}]}
[2018-08-21 16:52:33.981 - INFO] :shadow.build.npm/js-invalid-requires - {:resource-name "node_modules/node-pre-gyp/lib/util/versioning.js", :requires [{:line 17, :column 20}]}
And this in electron console:
Uncaught Error: browser bootstrap used in incorrect target
at Object.<anonymous> (/Users/endenwer/projects/electron-quick-start/cljs_output/main.js:2935:11)
at Object.<anonymous> (/Users/endenwer/projects/electron-quick-start/cljs_output/main.js:3050:3)
at Object.<anonymous> (/Users/endenwer/projects/electron-quick-start/cljs_output/main.js:3069:3)
at Module._compile (module.js:642:30)
at Object.Module._extensions..js (module.js:653:10)
at Module.load (module.js:561:32)
at tryModuleLoad (module.js:504:12)
at Function.Module._load (module.js:496:3)
at Module.require (module.js:586:17)
at require (internal/module.js:11:18)
I tried to install sqlite3 with node and everything works.
npm i && npm run rebuild-sqlitenpm start.View > Toggle Developer Toolsnpm run compile-cljs && npm run start-cljs/src/app.cljs. It only requires sqlite3 and do nothingshadow-cljs release appnode-script and add main function to cljs it will compile it without errors.I spend two days trying to solve this problem but I am out of ideas. I don't know if it is even possible with current version of shadow-cljs.
You can't compile sqlite3 for the browser since its not compatible with the browser.
You can however just set :js-options {:js-provider :require} in your build config.
{:source-paths ["src"]
:builds {:app {:target :browser
:output-dir "cljs_output"
:js-options {:js-provider :require}
:modules {:main {:entries [app]}}}}}
Typically a Browser doesn't have a require function but electron does so that should work. This way shadow-cljs won't process your node_modules at all and instead lets electron load them.
Thanks. It fixed error on compilation, but it is not working yet if I run compile or watch. If I run release everything works.
Fixed it. Thanks a lot for help. I am closing this issue.
Most helpful comment
You can't compile
sqlite3for the browser since its not compatible with the browser.You can however just set
:js-options {:js-provider :require}in your build config.Typically a Browser doesn't have a
requirefunction butelectrondoes so that should work. This wayshadow-cljswon't process yournode_modulesat all and instead letselectronload them.