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

The whole package.json content is shipped in the bundle #1322

Open
1 task done
tomchen opened this issue Mar 1, 2025 · 0 comments · May be fixed by #1323
Open
1 task done

The whole package.json content is shipped in the bundle #1322

tomchen opened this issue Mar 1, 2025 · 0 comments · May be fixed by #1323
Labels
bug unconfirmed not yet verified as an issue

Comments

@tomchen
Copy link

tomchen commented Mar 1, 2025

Please, check for existing issues to avoid duplicates.

  • No similar issues found.

What happened?

Hi, I noticed that the whole package.json is bundled in the distributed output of this library, including cjs, mjs, browser unminified and browser minified versions. This increases the size of this package and all downstream packages and apps unnecessarily, and expose metadata, including a long list of scripts, dependency names, and contributor emails, that isn't needed at runtime.

How can we reproduce the issue?

In https://unpkg.com/peerjs/dist/peerjs.min.js, search something like "contributors" or other keywords that appear in the package.json

What do you expected to happen?

Not include the whole package.json in the bundles

Environment setup

Any platform

peerjs v1.5.4 (latest), all cjs, mjs, browser unminified and browser minified versions

Is this a regression?

No response

Anything else?

It's due to these two:

import { version } from "../package.json";

import { version } from "../package.json";

Parcel can't treeshake this, even though it is ES module import. I guess many bundle tools can't, or intentionally don't treeshake such JSON file import, and include the whole JSON file content in the final output.

I'll create a PR

@tomchen tomchen added bug unconfirmed not yet verified as an issue labels Mar 1, 2025
tomchen added a commit to tomchen/peerjs that referenced this issue Mar 1, 2025
Using parcel's `inlineEnvironment` parcel-bundler/parcel#8470 (comment) to inline the version so the whole package.json content is not included in the bundle

Must use `"context": "browser"` for targets.main and targets.module, default context "node" can't inline `process.env.npm_package_version`

Added @types/node for `process`'s type definition

Closes peers#1322
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug unconfirmed not yet verified as an issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant