question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[ERROR] Could not resolve "pg-native" when making single file build output

See original GitHub issue

What 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:open
  • Created a year ago
  • Reactions:10
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
gdonoso94commented, Sep 1, 2022

Hi

Same problem over here, is there any solution or workaround?

1reaction
andrewbreycommented, Apr 11, 2022

@clintonwoo there is an open PR https://github.com/remix-run/remix/pull/1841 to expose the esbuild externals via configuration 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

Pg-native failing on webpack - Stack Overflow
The simple solution is to exclude pg-native in Webpack config. This works nicely. One gotcha is when I upgraded Webpack from 4 to...
Read more >
Plugins - esbuild
Plugins. The plugin API allows you to inject code into various parts of the build process. Unlike the rest of the API, it's...
Read more >
pg-native | Yarn - Package Manager
node-pg-native. Build Status. High performance native bindings between node.js and PostgreSQL via libpq with a simple API.
Read more >
serverless-bundle-no-pg-native - npm package - Snyk
Learn more about serverless-bundle-no-pg-native: package health score, ... If you'd like to ignore specific files, you can use a .eslintignore file.
Read more >
Unable to publish function using postgres - Build Plugins
Unable to deploy this: postgres function If I remove pg dependencies, it works: "pg": "^7.4.1", "pg-native": "^2.2.0", I also try to run it...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found