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.

` no such file or directory` shows when use `React.lazy`

See original GitHub issue

I have never modified the following default config.

webpack.config.renderer.dev.babel.js

output: {
    publicPath: `http://localhost:${port}/dist/`,
    filename: 'renderer.dev.js'
  },

webpack.config.renderer.prod.babel.js

output: {
    path: path.join(__dirname, '..', 'app/dist'),
    publicPath: './dist/',
    filename: 'renderer.prod.js'
  },

Everything works well, until I use React.lazy

App.js

const LazyMyHome = React.lazy(() => import('./Home'));
const MyHome = props => (
  <Suspense fallback={<span>Loading...</span>}>
    <LazyCreateProfile {...props} />
  </Suspense>
);

...
 <Route path="/" key="home" component={MyHome} />
...

npm run dev is ok while npm run start shows error in console.It looks like publicPath didn’t work. image.png

In fact, …/auto-perf-tool/app/dist/0.renderer.prod.js is the correct path.

Has anyone encountered the same problem?🥺

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
Holybasilcommented, Nov 18, 2020

@Unforgiven-wanda Actually, I am using React.lazy with preload: path.join(__dirname, 'dist/renderer.prod.js'). In this problem, it looks like the subpath dist is lost, maybe you can find something in webpack, and according to <script defer src="${script}"><\script>(when nodeIntegration: true ) , only files in the same directory as app.html can be requested.Apparently, it is unwise to put bundle files to app directory. The above are all my thoughts on this issue, and I don’t have time to continue researching, I hope it can help you.

0reactions
VitaliSakalouConeTeccommented, Feb 28, 2021

Hello, I have the same issue. Did anybody find a solution how to fix it? Thanks

Read more comments on GitHub >

github_iconTop Results From Across the Web

Building static HTML for pageserror: Error: ENOENT: no such ...
lazy suspense in your component which doesn't support server-side render, you need to remove it by any possible way. then try this should...
Read more >
Lazy loading in React - LoginRadius Blog
We will perform lazy loading with React suspense and without it. · First of all, create the app using npm create-react-app npm create-react-app...
Read more >
Lazy Loading React Components (with react.lazy and suspense)
It is a new function in react that lets you load react components lazily through code splitting without help from any additional libraries....
Read more >
Code-Splitting - React
Most React apps will have their files “bundled” using tools like Webpack, ... (such as a loading indicator) while we're waiting for the...
Read more >
How To Handle Async Data Loading, Lazy Loading, and Code ...
In future versions of React, you'll be able to use Suspense to load data in nested components without render blocking. In this tutorial,...
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