Turn on source maps by default (for dev + production) #7579
Replies: 17 comments 19 replies
-
My main concern here would be increasing build time, it'd be great to get insight into how much it's affected. |
Beta Was this translation helpful? Give feedback.
-
My concern is around sourcemaps in production.. it's essentially making your sourcecode available and readable to all. I would prefer to have them enabled on our dev and qa environments but turned off on production. We can then still perform lighthouse audits etc on those environments |
Beta Was this translation helpful? Give feedback.
-
I think there's still value developer tooling can gleam from dev-time source maps, but this is of course limited due to how often a production step can strip out library code that's really only there for your iteration workflow (think debugging helpers). Perhaps there's a sweetspot we can land on. One option is builds generate a production source map which can be used by developer insight tooling, but .map files are just not deployed to prod servers? |
Beta Was this translation helpful? Give feedback.
-
With regards to build times (cached production builds):
Retrieved these numbers while using next-source-maps. I used version With regards to whether source maps should be used in production, I agree that there might be things that are missed if they are only enabled during dev/qa environments. A build that generates production source maps that can be analyzed via tooling with the option of deploying them to prod servers (which I would prefer to be the default similar to CRA) sounds like a nice middle-ground. |
Beta Was this translation helpful? Give feedback.
-
I've written some thoughts regarding how we can approach source maps in this doc. |
Beta Was this translation helpful? Give feedback.
-
Curious to know if this will be a permanent RFC or if anybody in Zeit sees value in this? |
Beta Was this translation helpful? Give feedback.
-
Define "permanent RFC". It's being investigated. As you can see when sourcemaps get enabled build times almost double in many cases, making it really tricky as a default. |
Beta Was this translation helpful? Give feedback.
-
That's exactly the kind of info I wanted to hear after the numbers were shared! Thanks. Maybe there's a compromise in terms of offering it as part of config as opposed to a plugin? I'm okay with the increased build-time, for example. |
Beta Was this translation helpful? Give feedback.
-
Hey, we are facing the same problem trying to have Sentry configured as suggested here, but with a production build. |
Beta Was this translation helpful? Give feedback.
-
@anthanh , Have you managed to add the Sentry debugging to the production project? |
Beta Was this translation helpful? Give feedback.
-
The fact that we cant enable source maps for production to diagnose issues is a big issue. This plugin doesnt seem to work either for me: https://github.com/zeit/next-plugins/tree/master/packages/next-source-maps Debugging errors on client such as:
Without a proper stack trace etc is very difficult (source maps would be a massive help) |
Beta Was this translation helpful? Give feedback.
-
indeed it's very important and necessary to have source maps in all stages, during development, on the staging environment and also in production. as pointed out here debugging time is very important also I believe most users expect it to be turned on by default, at least me and every developer I know would expect that to happen from such incredible framework. most users have small projects so taking zeit.co as example of build time is unfair to the community specially new comer who are just starting to develop, if build time becomes a problem people can opt out. There are so many things on the documentation, having one page about how to optimise build time and any other kinds of optimisations would actually be more useful and productive than assuming people won't mind not having source maps on their project in 2020. |
Beta Was this translation helpful? Give feedback.
-
With Sentry example shows how to enable source maps in production, but only for token bearers. IMHO all we need is two new configuration params built into the core.
The second parameter can produce a custom API route behind the scence, i.e it will work when target is a Node.js server or Lambda fns (now.sh). |
Beta Was this translation helpful? Give feedback.
-
@timneutkens @rauchg I wonder if there's an incremental path we can take here... I like @housseindjirdeh's option 3 proposal of including source maps by default but requiring the developer to enable it themselves via next.config.js (so: lower barrier of use, but don't impact build times for everyone) // next.config.js
module.exports = {
options: {
sourcemaps: 'production' // possible values can be production, development, or none
}
} |
Beta Was this translation helpful? Give feedback.
-
Yep, I'm planning to add something like that soon. Currently working on finishing up a conference talk and will add it after that. |
Beta Was this translation helpful? Give feedback.
-
Stumbled upon this discussion in 2023. If anybody came to this page through search engine and is still looking for generating sourcemaps for prod, this nextjs doc might be helpful: https://nextjs.org/docs/advanced-features/source-maps. Not sure, if there is a easy way to skip deploying the generated sourcemaps in prod |
Beta Was this translation helpful? Give feedback.
-
This config https://nextjs.org/docs/advanced-features/source-maps will work if you use reference: https://nextjs.org/docs/pages/building-your-application/configuring/custom-server |
Beta Was this translation helpful? Give feedback.
-
Feature request
tl;dr: Can we please turn source map generation on for dev and production? :)
Is your feature request related to a problem? Please describe.
As of #943, Next.js does not output source maps by default. This is wee bit inconsistent with other popular React tooling such as CRA, which do output maps without developer opt-in when you
npm run build
ornpm run start
. I would like Next to consider changing this behavior to align with developer expectations of React scaffolding tooling.Overall, despite some discussion of shortcomings (e.g facebook/create-react-app#139), the CRA community appears to have found more value keeping source maps enabled than not. Preact CLI also outputs source maps by default in dev and prod builds.
Describe the solution you'd like
I would like Next.js to switch on source map generation for dev and production by default.
Reasons to turn them on:
Describe alternatives you've considered
An alternative to turning on source maps by default is a docs change where we just encourage more developers to opt into using source maps for dev and prod. I don't believe this will lead to as many developers getting the full advantages of having source maps turned on however... :)
cc @developit in case he has further input
Beta Was this translation helpful? Give feedback.
All reactions