Laravel-Vue项目发布帖子时出现Source Map 404错误求助
Let's tackle your issues one by one to get everything working smoothly:
That source map error happens because your browser is trying to load the Bootstrap source map file (bootstrap.js.map) to help with debugging, but either the file doesn't exist at the expected path or it's not being served correctly. Here are two ways to fix this:
Quick fix: Disable source maps temporarily
If you don't need source maps right now and just want to eliminate the error, you can turn them off in your build configuration (I’m assuming you’re using Laravel Mix since your code lives inresources/js). Update yourwebpack.mix.jsfile:mix.js('resources/js/app.js', 'public/js') .sourceMaps(false); // Disable source map generationThen recompile your assets with
npm run dev(for development) ornpm run prod(for production).Proper fix: Ensure the source map is correctly served
If you want to keep source maps for debugging:- Check if
bootstrap.js.mapexists in yournode_modules/bootstrap/dist/jsfolder. If it’s missing, reinstall Bootstrap withnpm install bootstrap --save. - Confirm your build tool is copying the source map to your
public/jsdirectory. Laravel Mix does this automatically by default, but if you have custom webpack rules, double-check that source map files are being output correctly. - Verify the source map reference in your compiled
app.jsfile. At the end of the file, you should see a comment like//# sourceMappingURL=bootstrap.js.map— make sure this path matches where the actual.mapfile lives in yourpublic/jsfolder.
- Check if
Looking at your app.js code, there are a couple of things that might cause problems down the line:
Incorrect Axios Request URL
Your current request URL is'myid.web/home/addPost'— this will make the browser send a request tohttp://{mywebsite}/myid.web/home/addPost, which is probably not your actual API endpoint. Instead, use a root-relative path if your route is on the same domain:axios.post('/home/addPost', { content: this.content })Incomplete Catch Block
You haveconsole.log...in your catch handler, which is invalid syntax. Fix it to properly log errors so you can debug any request issues:.catch(function(error){ console.log(error); // Log full error details to debug })Improve Context with Arrow Functions
For cleaner code and to keep access to the Vue instance'sthisinside your promise handlers, use arrow functions:addPost(){ axios.post('/home/addPost', { content: this.content }) .then(response => { console.log(response); this.content = ''; // Optional: Clear input after successful post }) .catch(error => { console.log(error); }) }
After making these changes, recompile your assets and test again — both the source map error and any potential request issues should be resolved.
内容的提问来源于stack exchange,提问作者Biswas Sampad

