question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Export Analysis reports wrong sizes

See original GitHub issue

Describe the bug

https://bundlephobia.com/result?p=@timvir/core@0.0.14

The size of the fullWidth and extendedWidth should be a few bytes, not 9kB! If you look at the source (https://unpkg.com/browse/@timvir/core@0.0.14/index.js), the extendedWidth export is essentially this:

function cx(...classNames) {
  return classNames.filter(Boolean).join(' ');
}

const noLayout = "n13r7o41";
export const extendedWidth = cx(noLayout, "ev9kr8h");

To Reproduce

Source and output from bundlephobia available in the links above.

Expected behavior

The size of the fullWidth and extendedWidth exports should be a few bytes. The whole block above is only ~163 bytes (uncompressed).

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:8
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
pablo-abccommented, Jan 19, 2022

Upon further inspection I think I found a solution to this. Removing the "browser" property from my package’s package.json, or pointing it to the esm output makes Bundlephobia report the correct sizes now as seen here. The only thing I find weird about this is that package-build-stats correctly pointed the path to my esm output, even if it wasn’t using that one to calculate the sizes?

There’s basically three things required for Bundlephobia to report the correct sizes of each module on its “Export Analysis”:

  1. Your exported modules should each be in a separate file
  2. Your bundler should preserve said modules in separate files (in rollup this would mean either using multiple entry points, or using output.preserveModules = true).
  3. Your package.json should point its "browser" property to your esm bundle, not umd nor cjs.

I’m not sure if this is a bug in Bundlephobia, but webpack does tree shake properly regardless of the "browser" property (as per my previous comment).

0reactions
pablo-abccommented, Jan 18, 2022

I’m having the same issue with some of my packages. This one being a great example since it’s just a bunch of utils. I’m using Rollup to bundle these packages but I have confirmed in a simple project that webpack does tree shake unused imports. This is how I’m testing it:

// webpack.config.js
const path = require('path');

module.exports = {
  entry: './src/index.js',
  output: {
    filename: 'main.js',
    path: path.resolve(__dirname, 'dist'),
  },
  mode: 'development',
  optimization: {
    usedExports: true,
    innerGraph: true,
    sideEffects: true,
  },
  devtool: false,
};
// src/index.js
import { _get } from '@felte/common';

const res = _get({ prop: 'value' }, 'prop');
console.log(res);
// package.json
{
  "main": "index.js",
  "scripts": {
    "build": "webpack"
  },
  "devDependencies": {
    "webpack": "^5.66.0",
    "webpack-cli": "^4.9.1"
  },
  "dependencies": {
    "@felte/common": "0.6.0"
  }
}

The resulting bundle does tree-shake everything but _get. But, unless I’m understanding incorrectly what Bundlephobia’s export analysis does, it’s implying this would bundle 2.3kb instead of the few bytes that the method itself uses.

Note: these are all named exports, exported from a single index.js file.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Troubleshoot problems running or exporting a report
Technical issues are usually the reason a report fails to run or export. For example, reports containing very long date ranges may timeout...
Read more >
SSRS: Wrong Paper Size Set When Exporting Landscape...
Hi,. I've come across a strange problem with SSRS reports when exporting to Word. I have a report which needs to fit onto...
Read more >
How can I get bundlephobia to show different sizes in export ...
So I'm using bundlephobia to audit the bundle size of my packages. Bundlephobia has a section called "Export Analysis" that gives you the ......
Read more >
Export to PDF not Exprting to correct Size
Make sure you have the filter pane collapsed when you export the PDF, I had to do that in order to get rid...
Read more >
Exporting reports - Oracle Help Center
You can use the reporting API to export data from your reports. From the reporting UI, you can export report data in CSV,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found