CSS sourceMappingURL is wrong in "productionBrowserSourceMaps: true" mode
See original GitHub issueWhat version of Next.js are you using?
10.2.3
What version of Node.js are you using?
12.22.1
What browser are you using?
Chrome
What operating system are you using?
Linux
How are you deploying your application?
next start
Describe the Bug
When I enabled sourceMaps in prod mode:
// next.config.js
module.exports = {
productionBrowserSourceMaps: true,
}
css sourcemaps are broken, because all CSS code is fetch by XHR and inserted to page by <style>
tag with wring relative sourceMappingURL
path.
Example:
Page got this css https://some.app/_next/static/css/02de173fd9311ea5fb00.css
with /*# sourceMappingURL=02de173fd9311ea5fb00.css.map*/
inside
but next.js add this css code manually to header
like here
as a result browser try to get sourcemap here: https://some.app/doc/02de173fd9311ea5fb00.css.map instead of correct path here https://some.app/_next/static/css/02de173fd9311ea5fb00.css.map.
Expected Behavior
Trying to get sourcemap by correct path: https://some.app/_next/static/css/02de173fd9311ea5fb00.css.map
To Reproduce
- Build any project with
css
withproductionBrowserSourceMaps: true
option - Start builded project
- Open page in Chrome with DevTools
Issue Analytics
- State:
- Created 2 years ago
- Reactions:5
- Comments:6
Top Results From Across the Web
nextConfig issue while building or running the project #39161
It can potentially be dangerous for plugins to extend the Next.js config that it does not recognize as this might lead to unexpected...
Read more >Advanced Features: Source Maps | Next.js
Enables browser source map generation during the production build.
Read more >Webpack doesn't emit css sourcemap (with sourcemap: true)
I need this source map in dev mode, but only two files get emited main.css and bundle.js. javascript · css · webpack ·...
Read more >Should I Use Source Maps in Production? | CSS-Tricks
I agree that sourcemap files should be deployed on production. If one is worried about showing their “real code”, Webpack has a feature...
Read more >Warning: -file- is being assigned a //# sourceMappingURL, but ...
What went wrong? A source map has been specified more than once for a given JavaScript source. JavaScript sources are often combined and...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Idk how much it helps, but these source map errors were pretty annoying to me. As a workaround until this issue is fixed, I wrote a simple webpack plugin that rewrites the
sourceMappingURL
to an absolute pathDefinitely don’t need to use the
done
hook to do this. If you usedemit
, you wouldn’t have to read the content of the disk. I usedone
because I have other hooks running duringemit
that don’t like the absolute source map location, and then anotherdone
hook that needs to run before I finally update the source map path.Plugin
Usage
@johnruane I just made middleware that ignores all requests with
css.map
😢