Skip to content

Bundling with rollup #1906

@rowanwins

Description

@rowanwins

Just dropping a note here because I spent a few hours on this :)

I was attempting to bundle pg using rollup for deployment into a lambda function. While the bundling process would work when I attempted to run my server I'd get an error along the line of

Error: Cannot find module 'pg-native'

I ended up resolving the issue by specifying a couple of ignores with rollup-plugin-commonjs. My complete rollup config looked something like

import json from 'rollup-plugin-json'
import resolve from 'rollup-plugin-node-resolve'
import commonjs from 'rollup-plugin-commonjs'

export default {
  input: 'src.js',
  output: {
    file: 'output.js',
    format: 'cjs'
  },
  plugins: [
    resolve(),
    commonjs({
      include: 'node_modules/**',
      ignore: ['pg-native' , './native'] <---- the critical lines
    })
  ]
}

I took my lead from these lines with pg which suggest that the require(./native) leads to the inclusion of the require(pg-native)

Hope this helps somebody else one day :)

Thanks for a super library!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions