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.

Typescript pulling all MUI files - super slow compilation

See original GitHub issue
  • This is a v1.x issue (v0.x is no longer maintained).
  • I have searched the issues of this repository and believe that this is not a duplicate.

Expected Behavior

TSC should compile in about 3-8 seconds.

Current Behavior

TSC takes over 1 minute to compile, because it’s pulling the entire library, with over half a million types. running tsc --extendedDiagnostics --listFiles --noEmit image

and it goes on…

image

If I remove the MUI folder (resulting in lots of errors of course) image

Context

I’m only using 10 components in the entire app, all imported like this: import CircularProgress from '@material-ui/core/CircularProgress/CircularProgress';

It should only import the relevant files and types.

My tsconfig:

{
  "compilerOptions": {
    "baseUrl": "./src",
    "outDir": "build/dist",
    "target": "es5",
    "lib": ["es6", "es7", "dom"],
    "sourceMap": true,
    "allowJs": false,
    "jsx": "react",
    "esModuleInterop": true,
    "skipLibCheck": true,
    "moduleResolution": "node",
    "allowSyntheticDefaultImports": true,
    "rootDir": "./src",
    "noEmitOnError": false,
    "isolatedModules": true,
    "strictPropertyInitialization": false,
    "forceConsistentCasingInFileNames": true,
    "noFallthroughCasesInSwitch": true,
    "noErrorTruncation": true,
    "noImplicitReturns": true,
    "noImplicitAny": true,
    "noImplicitThis": true,
    "strictNullChecks": true,
    "diagnostics": true,
    "suppressImplicitAnyIndexErrors": true,
    "noUnusedLocals": true
  },
  "include": [
    "src/**/*"
  ],
  "exclude": [
    "dist",
    "build",
    "node_modules",
    "src/**/__tests__"
  ],
  "defaultSeverity": "warning"
}

My @types folder: image

Any ideas why this happens?

Thank you for your help!!!

Your Environment

Tech Version
Material-UI v1.2.2
React latest
browser
etc

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:4
  • Comments:11 (3 by maintainers)

github_iconTop GitHub Comments

21reactions
jtreminiocommented, Oct 15, 2018

@manpreetnarang instead of

import {
  AppBar,
  Button,
  Hidden,
  IconButton,
  Toolbar,
} from '@material-ui/core';
import { Menu } from '@material-ui/icons';

Do this:

import AppBar from '@material-ui/core/AppBar';
import Button from '@material-ui/core/Button';
import Hidden from '@material-ui/core/Hidden';
import IconButton from '@material-ui/core/IconButton';
import Toolbar from '@material-ui/core/Toolbar';

import Menu from '@material-ui/icons/Menu';
6reactions
weswighamcommented, Jun 29, 2018

This is an issue with Typescript, not with MUI. There is nothing MUI can do about this

@Pajn Actually while we definitely do (did? we should be publishing a fix on nightlies tonight) have a perf problem, there’s an issue in MUI that is causing us to do more work than we should need to for a given deep import, too (which is why the file count goes up so much with a single component import)! Specifically, you have imports like this one:

import { StandardProps } from '..';

That import references the root index.d.ts - your root index.d.ts imports all components (to reexport them), causing us to load every type definition in MUI (we won’t typecheck them unless requested, but we will load them all from disk and parse them, which has a cost). If you moved your utilitity types like StandardProps into a separate file from the root index.d.ts and did a direct import of them, it would cut down on the fileset loaded for a given component fairly significantly.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Typescript pulling all MUI files - super slow compilation #11916
I'm only using 10 components in the entire app, all imported like this: import CircularProgress from '@material-ui/core/CircularProgress/ ...
Read more >
Typescript compiling very slowly - Stack Overflow
I was wondering if splitting the index.d.ts file into smaller files would help? It would be really helpful is someone could please provide...
Read more >
Minimizing bundle size - Material UI - MUI
Size snapshots are taken on every commit for every package and critical parts of ... we can inspect detailed bundle size changes on...
Read more >
Build strongly typed polymorphic components with React and ...
In this detailed (and explanatory) guide, I'll discuss how to build strongly typed polymorphic React components with TypeScript.
Read more >
Build is extremely slow at the end - Netlify Support Forums
My guess is that pulling many small files in parallel is just somehow faster than pulling one monolith of a cache. Our cache...
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