Skip to content

package.json "browser" field used on the server side #12253

@btakita

Description

@btakita

Describe the bug

I'm working on a PR for papaparse to support ESM.

mholt/PapaParse#978

Part of the solution is to add package.json into the esm directory:

{
	"main": "./index.mjs",
	"browser": "./index.browser.mjs"
}

When I run this using vite, by way of astro.js, the following error occurs:

/@fs/home/brian/work/portfoliome/censible-core/vendor/PapaParse/papaparse.js:920
                var Duplex = require('stream').Duplex;
                             ^

ReferenceError: require is not defined
    at new DuplexStreamStreamer (/@fs/home/brian/work/portfoliome/censible-core/vendor/PapaParse/papaparse.js:920:16)

The problem is the "browser" export is used instead of the "main" export on the server side.

Reproduction

mholt/PapaParse#978

Steps to reproduce

Use commit 12d09d54f6e79f05eabb5fb61f0de582ff63f511 as a dependency to a vite server side project or an astro.js project.

System Info

System:
    OS: Linux 6.1 Arch Linux
    CPU: (16) x64 AMD Ryzen 7 5800X 8-Core Processor
    Memory: 36.83 GB / 62.71 GB
    Container: Yes
    Shell: 5.9 - /usr/bin/zsh
  Binaries:
    Node: 18.14.0 - ~/.config/nvm/versions/node/v18.14.0/bin/node
    Yarn: 1.22.19 - /usr/bin/yarn
    npm: 9.3.1 - ~/.config/nvm/versions/node/v18.14.0/bin/npm
  Browsers:
    Brave Browser: 110.1.48.164
    Chromium: 110.0.5481.100
    Firefox: 110.0

Used Package Manager

npm

Logs

/@fs/home/brian/work/portfoliome/censible-core/vendor/PapaParse/papaparse.js:920
                var Duplex = require('stream').Duplex;
                             ^

ReferenceError: require is not defined
    at new DuplexStreamStreamer (/@fs/home/brian/work/portfoliome/censible-core/vendor/PapaParse/papaparse.js:920:16)

Validations

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions