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.

How to obtain production environment react.lazy Our support

See original GitHub issue

Is your feature request related to a problem? Please describe.

react.lazy Itā€™s available during development, like this

const Component = lazy(() => import(`../pages${page}`));

But after build, the import failed

Describe the solution youā€™d like

After build, it can work normally

Describe alternatives youā€™ve considered

Additional context

I just tried to use vite in react to see if I could migrate from CRA šŸ˜Œ

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
ppblcommented, Feb 21, 2021

@jonaskuske Thank you very much.šŸ‘

Try to add a file extension to your import statement, e.g.

import(`../pages/${page}.js`)

Vite is using rollup for its build, so I assume the same limitations apply when it comes to dynamic imports: https://github.com/rollup/plugins/tree/master/packages/dynamic-import-vars#limitations

Iā€™ve looked at the restrictions again, and now I understand

Two main points

  1. There must be a static part
  2. Must end with extension
import(`../pages/${page}/index.tsx`)

Since my page was a directory, I need to add it now index.tsx

And dynamic import vars has been introducedšŸ˜‚

Okay, I feel like Iā€™m stupid. Iā€™ll close this issue lateršŸ¤¦ā€ā™‚ļø

0reactions
jonaskuskecommented, Feb 21, 2021

Awesome, glad I could help! šŸ¤ž

Read more comments on GitHub >

github_iconTop Results From Across the Web

React Lazy Loading: The Best Complete Guide - CopyCat Blog
Learn how to optimize your app with a complete guide to React lazy loading and code splitting with coding examples, tips, videos, and...
Read more >
Lazy loading React components - LogRocket Blog
Using React.ā€‹ā€‹ React. lazy() makes it easy to create components that are loaded using dynamic import() but rendered like regular components. ThisĀ ...
Read more >
React lazy loading and performance - Retool
The React.lazy() function allows you to render a dynamic import as a normal component. It makes it simple to construct components that areĀ ......
Read more >
Setup Development and Production Environment for React App
Step 2: Let's add react and webpack in our project. Run the below command to install react and webpack. npm install react react-dom...
Read more >
React.lazy not working in production mode - Stack Overflow
Like I mentioned in the question, the babel-minify-webpack-plugin was causing the issue for some reason. My guess is, they were savingĀ ...
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