Skip to content
This repository was archived by the owner on Aug 12, 2025. It is now read-only.

Usage of Node process module pulls in ~3KB shim when building #57

@Daniel15

Description

@Daniel15

Versions

  • 0.3.8

Describe the bug

I'm using Parcel to build the JS for one of my sites. This code in the Plausible tracker:

if (
!(
typeof process !== 'undefined' &&
process &&
process.env.NODE_ENV === 'test'
)
) {
setTimeout(() => {
// eslint-disable-next-line functional/immutable-data
location.href = this.href;
}, 150);
}

Causes Parcel to pull in a ~3KB (minified) shim for the Node.js process module. This is the code that gets bundled: https://github.com/defunctzombie/node-process/blob/master/browser.js

This can be avoided with the following Parcel config in package.json:

  "alias": {
    "process": false
  }

but this shouldn't be necessary.

Expected behavior

Tracker should be as lightweight as possible and not pull in unnecessary shims. Since the code causing this issue is only for testing, it shouldn't exist at all in the production build of the library. Potentially this code could be implemented using a mock in the test, rather than modifying the library itself to perform differently under test.

Steps to reproduce

Steps:
Create analytics.js, for example:

import Plausible from 'plausible-tracker';

const {trackPageview, enableAutoOutboundTracking} = new Plausible({
  apiHost: 'https://example.com',
  trackLocalhost: true,
});

trackPageview();
enableAutoOutboundTracking();

Run parcel on it, e.g.

yarn install parcel
.\node_modules\.bin\parcel build analytics.js

Observe the resulting dist/analytics.js file.

Your Environment

N/A

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions