Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Daniel15 opened this issue Oct 13, 2023 · 1 comment
Open

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

Daniel15 opened this issue Oct 13, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@Daniel15
Copy link

Daniel15 commented Oct 13, 2023

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

@Daniel15 Daniel15 added the bug Something isn't working label Oct 13, 2023
@Daniel15 Daniel15 changed the title Usage of Node process module pulls in ~3KB process shim when building Usage of Node process module pulls in ~3KB shim when building Oct 13, 2023
@Barbapapazes
Copy link

Hello,

Since this package have not been update for two years, I made a fork.

I rewrite the tracker to be more modular and I fix this issue.

https://github.com/Barbapapazes/plausible-tracker

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants