[ERROR] Could not resolve "pg-native" when making single file build output
See original GitHub issueWhat version of Remix are you using?
1.3.5
Steps to Reproduce
Seems like ESBuild is throwing an error when using pg
package and remix.config.js serverDependenciesToBundle: [/^.*$/]
to produce a single file server build. The problem seems because the pg library uses lazily required natively built bindings that are only peer dependencies.
In remix 1.3.2
I can just modify the regex to avoid bundling it (serverDependenciesToBundle: [/^(?!pg-native).*$/]
) but in remix 1.3.5
there’s an additional error after about module onResolve from @remix-run/dev/compiler/plugins/serverBareModulesPlugin.js
. Seems like the onResolve thing has been added after 1.3.2 at some point which is causing a problem with the unbundled module.
Marking pg-native as external (external: ['pg-native']
) in ESBuild works as expected but Remix is not providing any API to modify ESBuild config.
Expected Behavior
The remix build should output the bundled build file without pg-native
included since it doesn’t exist in this context (it’s a peer dependency and I’m not installing, building or using it).
Actual Behavior
Error msg:
Building Remix app in production mode...
✘ [ERROR] Could not resolve "pg-native"
node_modules/pg/lib/native/client.js:4:21:
4 │ var Native = require('pg-native')
╵ ~~~~~~~~~~~
You can mark the path "pg-native" as external to exclude it from the bundle, which will remove this error. You can also surround this "require" call with a try/catch block to handle this failure at run-time instead of bundle-time.
Issue Analytics
- State:
- Created a year ago
- Reactions:10
- Comments:6 (1 by maintainers)
Hi
Same problem over here, is there any solution or workaround?
@clintonwoo there is an open PR https://github.com/remix-run/remix/pull/1841 to expose the esbuild
externals
via configuration 👍