Open dgrimaldi-intellyse opened 6 months ago
I have also encountered this issue.
Using --turbo seems mitigate the issue, at least in local
Using --turbo seems mitigate the issue, at least in local
Thanks for the info, I will try at home. Hopefully they fix the root cause soon.
Using --turbo seems mitigate the issue, at least in local
I can agree it mitigates the issue on v14.1.3
Having the same issue with Tailwind Template: Studio. Confirmed testing with --turbo seems to mitigate...
Same issue on node v20.16.0 and Next v14.2.5
Where do you use --turbo as a workaround ? On start command ?
Same issue on node v20.16.0 and Next v14.2.5
Where do you use --turbo as a workaround ? On start command ?
In the package.json at dev command
"dev": "next dev --turbo",
@dgrimaldi-intellyse I just had this issue in my production app. Occurred only once but is there a proper work around? I am using next: 14.2.5. Is there any solution that you found?
Has anyone found a definitive solution for the chunk loading issue?
I’ve been looking into this problem, which seems to have started in version 13.3.4 of Next.js, and it continues to affect all subsequent versions, including the pre-release version 15.0.0.canary.
Some people suggest that removing the .next folder clears the cache and temporarily fixes the issue, but this solution isn’t viable for production environments, where such an approach could cause more problems. Others have implemented workarounds like forcing a page reload when the error is detected, but these are not ideal solutions either.
So far, I haven’t seen anyone in the community find a solid fix, and it seems like the newer versions of Next.js aren’t addressing this issue, possibly because it’s considered an “old” bug that started in version 13.3.4. We know it’s related to Webpack, but is there any viable alternative to Webpack for production environments at the moment?
I have this issue as well, it's quite frustrating. Hopefully, it will be resolved soon.
Same. The issue in in production. Seeing lots of errors about it in Sentry. Never happens in local dev for me.
I was able to solve the issue by removing dynamic imports of components. I opted state based rendering of these components.
Auto-detecting and reloading failed chunks in my global layout.tsx worked for me. Not sure its the ideal solution but seems to resolve the problem.
<script dangerouslySetInnerHTML={{
__html: `
// Track failed chunks
window.__failedChunks = new Set();
// Retry loading failed chunks
function retryLoadChunk(url, maxRetries = 3) {
if (window.__failedChunks.has(url)) return;
let retries = 0;
const loadScript = () => {
if (retries >= maxRetries) {
window.__failedChunks.add(url);
return;
}
retries++;
const script = document.createElement('script');
script.src = url;
script.async = true;
script.onerror = () => {
setTimeout(loadScript, 1000 * retries);
};
document.head.appendChild(script);
};
loadScript();
}
// Handle errors and retry chunk loading
window.onerror = function(msg, url, lineNo, columnNo, error) {
if (url?.includes('/_next/') &&
(msg.includes('chunk') || msg.includes('Syntax'))) {
retryLoadChunk(url);
}
return false;
};
// Handle script load failures
window.addEventListener('error', function(event) {
if (event.target?.tagName === 'SCRIPT') {
const src = event.target.src;
if (src.includes('/_next/')) {
retryLoadChunk(src);
event.preventDefault();
}
}
}, true);
`
}} />
Link to the code that reproduces this issue
https://github.com/Intellyse/next-js-bug
To Reproduce
Current vs. Expected behavior
Provide environment information
Which area(s) are affected? (Select all that apply)
Webpack
Which stage(s) are affected? (Select all that apply)
next dev (local)
Additional context
The error seems happen randomly, and we have this issue also in production. It seems related with something with webpack
the error rise at line: var error = new Error();