Node-postgres: Using 'pg' in webpack to Electron return an error trying to requiring pg-native.

Created on 26 Sep 2016  路  5Comments  路  Source: brianc/node-postgres

Hi!

I'm trying to use this bundled with webpack to be used in electron. But it tries to import the pg-native module. I really don't know how to use the native binding in Electron, but at least I would like to be able to use the plain JS driver.

I read #127 and #838, and commenting the lines mentioned here makes the package works, but I see this most like a workarround. The problem it's not gone, just hided.

Thanks!

EDIT: You can test this here

npm run build:electron

Main and Renderer process will be packaged in separated files. The Renderer part will be packaged correctly, but when it tries to bundle the Main part the error will be thrown.

Most helpful comment

Does making pg/native part of externals in the webpack configuration work?

externals: [
    "pg/native",
],

All 5 comments

aaaaaaaaaaand its still not. Nor can I find any workarounds :(

@rozzzly for workarounds you can comment some lines as I said in the description.

Does making pg/native part of externals in the webpack configuration work?

externals: [
    "pg/native",
],

Just tested @charmander solution with Electron, having suffered from the same issue like @michaeljota, works great! I think this should be noticed in the docs and this issue can be closed.

As of pg 8.2.1, I am using this webpack config workaround, which hopefully most can stomach until a permanent fix is released:
https://github.com/brianc/node-postgres/issues/838#issuecomment-405646013

The other thing to keep in mind is that you mustn't run postgres queries from a renderer process.

Was this page helpful?
0 / 5 - 0 ratings