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.

large production bundle size in typescript react app

See original GitHub issue

Do you want to request a feature or report a bug?

Bug

What is the current behavior?

Recharts loading entire index.js

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem via https://jsfiddle.net or similar (template: http://jsfiddle.net/ndLhnegs/).

https://github.com/vigyanhoon/the-list this repo has the code. Also attached is the production build analysis

I have included charts in Graph1 and Graph2 like so

import { LineChart, Line, XAxis, YAxis, CartesianGrid, Tooltip, Legend, ResponsiveContainer } from ‘recharts’;

I have also added types “@types/recharts”: “^1.8.12”,

When I try to import using this import LineChart from 'recharts/es6/chart/LineChart' it gives following error: Could not find a declaration file for module ‘recharts/es6/chart/LineChart’. ‘c:/Users/vigya/Desktop/projects/the-list/node_modules/recharts/es6/chart/LineChart.js’ implicitly has an ‘any’ type. If the ‘recharts’ package actually exposes this module, consider sending a pull request to amend 'https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/recharts`

What is the expected behavior?

It should only include components that I have used.

Which versions of Recharts, and which browser / OS are affected by this issue? Did this work in previous versions of Recharts?

Windows 10 and “recharts”: “^1.8.5”,

image

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:22
  • Comments:13

github_iconTop GitHub Comments

5reactions
monsieurnebocommented, Aug 11, 2022

I just tried the recharts/es6/ import method, and my bundle is still crazy big.

Any lead on recharts optimization? It is the biggest part of my production bundle 😐

4reactions
goenningcommented, Nov 22, 2020

I have a workaround in case someone is looking for it.

Import from es6 and export it alongside it’s type definition:

import type { ResponsiveContainer, AreaChart, Area, XAxis, YAxis, Tooltip } from 'recharts'

const ResponsiveContainerImpl: typeof ResponsiveContainer = require('recharts/es6/component/ResponsiveContainer').default
const AreaChartImpl: typeof AreaChart = require('recharts/es6/chart/AreaChart').default
const AreaImpl: typeof Area = require('recharts/es6/cartesian/Area').default
const XAxisImpl: typeof XAxis = require('recharts/es6/cartesian/XAxis').default
const YAxisImpl: typeof YAxis = require('recharts/es6/cartesian/YAxis').default
const TooltipImpl: typeof Tooltip = require('recharts/es6/component/Tooltip').default

export {
  ResponsiveContainerImpl as ResponsiveContainer,
  AreaChartImpl as AreaChart,
  AreaImpl as Area,
  XAxisImpl as XAxis,
  YAxisImpl as YAxis,
  TooltipImpl as Tooltip,
}

And then import it from that instead of recharts:

import { Area, AreaChart, ResponsiveContainer, Tooltip, XAxis, YAxis } from 'path/to/file/above'

Once this issue is fixed, it’ll be easy to just remove that file and import directly from recharts.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Two Quick Ways To Reduce React App's Size In Production
File size Development v/s Production. 2. Serve gzipped file in production. You can dramatically reduce the size by gzipping the bundle.js.
Read more >
Analyze your React app's bundle size and reduce it using ...
The bundle size in development mode will be much larger than in production mode, so don't get too scared if it looks huge!...
Read more >
[Question] ReactJS + TypeScript = larger bundle size
I know TS adds a lot of good stuff into the app but I wonder about the bundled size of the project. How...
Read more >
Reduce your React Applications Bundle Size by 75% with ...
One of the most impactful techniques to reduce the bundle size of a React application is compression. compression is a process in which...
Read more >
5 Methods to Reduce JavaScript Bundle Size
Webpack uses a dependency graph to generate bundles, and this graph consists of every module we use within an application. As the application...
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