React项目出现index.jsx.js 404错误,求排查方案
index.jsx.js 404 Error in Your React + Webpack App Hey there, let's work through this confusing 404 issue together—that extra .js suffix on your filename is definitely odd, but we can track it down. Here are the most common places to investigate:
Double-check your Webpack entry configuration
Pop open yourwebpack.config.jsand look at theentryfield. It’s easy to accidentally add an extra.jssuffix here, like writing./app/index.jsx.jsinstead of./app/index.jsx. Also, check theresolve.extensionsarray—if it’s set to something like['.js', '.jsx'], make sure you aren’t forcing an unnecessary suffix in your entry path (Webpack should automatically resolve the correct extension based on this list).Inspect your HTML’s script tag
If you’re manually adding a script tag in yourindex.htmlto load the bundle, verify thesrcattribute. A typo here (like<script src="/app/index.jsx.js"></script>) would directly cause this 404. If you’re usinghtml-webpack-plugin, check its configuration to ensure it’s not generating an incorrect script path.Search for accidental
index.jsx.jsreferences
Do a full project search for the stringindex.jsx.js—it’s possible you made a typo in animportstatement somewhere (e.g.,import Component from './index.jsx.js'). Even one misplaced reference could trigger Webpack to try resolving this non-existent file.Review Webpack’s output settings
Look at theoutputsection in your config. If thefilenameproperty is set to something like[name].jsx.js, that would cause Webpack to generate a bundle with the double suffix. Also, check thepublicPathvalue—an incorrect public path might be appending extra segments to your file URL.Check DevServer configuration
If you’re usingwebpack-dev-server, verify thestatic(orcontentBasein older versions) setting. A misconfigured static directory could lead the server to look for files in the wrong location. Also, rule out any proxy rules that might be redirecting requests incorrectly.Clear cache and restart your dev server
Sometimes Webpack’s cached build artifacts can cause weird, inconsistent issues. Try deleting thenode_modules/.cachedirectory, stopping your dev server, and restarting it with a fresh build.
内容的提问来源于stack exchange,提问作者RockDev

