Skip to content

Commit

Permalink
Enable source mapping in Next.js
Browse files Browse the repository at this point in the history
For source-mapped backtraces to be emitted for Next.js backend errors
when Next.js is running in production mode, the webpack configuration
needs to be tweaked in order to emit backtraces, and the
`--enable-source-maps` flag needs to be passed to the Node.js runtime
when starting the Next.js application, using the `NODE_OPTIONS`
environment variable.
  • Loading branch information
unflxw committed Jul 26, 2024
1 parent 6bdb75d commit bc73f64
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 4 deletions.
6 changes: 6 additions & 0 deletions nodejs/nextjs-13-app/app/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ const nextConfig = {
// Add the following line inside the object
instrumentationHook: true,
},
webpack: (config, {isServer}) => {
if (isServer) {
config.devtool = 'eval-source-map'
}
return config
}
};

module.exports = nextConfig
2 changes: 1 addition & 1 deletion nodejs/nextjs-13-app/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"start": "NODE_OPTIONS=--enable-source-maps next start",
"lint": "next lint"
},
"dependencies": {
Expand Down
6 changes: 6 additions & 0 deletions nodejs/nextjs-13-pages/app/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ const nextConfig = {
experimental: {
instrumentationHook: true,
},
webpack: (config, {isServer}) => {
if (isServer) {
config.devtool = 'eval-source-map'
}
return config
}
}

module.exports = nextConfig
2 changes: 1 addition & 1 deletion nodejs/nextjs-13-pages/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"start": "NODE_OPTIONS=--enable-source-maps next start",
"lint": "next lint"
},
"dependencies": {
Expand Down
6 changes: 6 additions & 0 deletions nodejs/nextjs-14-app/app/next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ const nextConfig = {
instrumentationHook: true,
serverComponentsExternalPackages: ['@appsignal/nodejs'],
},
webpack: (config, {isServer}) => {
if (isServer) {
config.devtool = 'eval-source-map'
}
return config
}
};

export default nextConfig;
2 changes: 1 addition & 1 deletion nodejs/nextjs-14-app/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"start": "NODE_OPTIONS=--enable-source-maps next start",
"lint": "next lint"
},
"dependencies": {
Expand Down
6 changes: 6 additions & 0 deletions nodejs/nextjs-14-pages/app/next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ const nextConfig = {
instrumentationHook: true,
serverComponentsExternalPackages: ['@appsignal/nodejs'],
},
webpack: (config, {isServer}) => {
if (isServer) {
config.devtool = 'eval-source-map'
}
return config
}
};

export default nextConfig;
2 changes: 1 addition & 1 deletion nodejs/nextjs-14-pages/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"start": "NODE_OPTIONS=--enable-source-maps next start",
"lint": "next lint"
},
"dependencies": {
Expand Down

0 comments on commit bc73f64

Please sign in to comment.