Skip to content

Bug: Wrong use of the package.json browser field #58

@Download

Description

@Download

I notice in this example that it is referencing the umd build in the dist folder in the browser field of package.json:

{
  "main": "dist/how-long-till-lunch.cjs.js",
  "module": "dist/how-long-till-lunch.esm.js",
  "browser": "dist/how-long-till-lunch.umd.js",
}

Thinking of interop with other tools, I wonder whether this is right?

I think Browserify and Webpack both use the browser field as having the meaning 'the entry point for this package, for browsers'. But they assume 'normal' cjs code.

For example have a look at the browser field in the package.json of debug:

{
  "main": "./src/index.js",
  "browser": "./src/browser.js",
  "unpkg": "./dist/debug.js"
}

Notice how they use a file in the src folder here. Both Browserify and Webpack will pick up this file and package / bundle it, wrapping it with a umd wrapper for umd builds.

So I wonder, is it right that the file this project is setting for the browser field is a umd build, that already has a umd wrapper? Won't this file end up being wrapped twice?

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