Skip to content

Webpack resolves browser package module by default #138

Closed
@dobromir-hristov

Description

@dobromir-hristov

OK so I am writing this so other people dont waste hours like me.

Issue

Your function works when you manually tested and with simple express server, but throws errors in both serve and build modes of netlify-lambda.

Possible Cause

It may be that one of the dependencies has a browser field defined in its package.json (could be indirect dep), which in most cases is not compatible with Node, but Webpack by default prefers it over main or module definitions.

Solution

Create a webpack.functions.js file in with a modified resolver, so it skips the browser bundle

module.exports = {
  resolve: {
    mainFields: ['module', 'main']
  }
}

Then run your command

netlify-lambda serve functions --config ./webpack.functions.js

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions