sentry-javascript
sentry-javascript copied to clipboard
NextJS TypeScript types are incorrect
Is there an existing issue for this?
- [X] I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues
- [X] I have reviewed the documentation https://docs.sentry.io/
- [X] I am using the latest SDK release https://github.com/getsentry/sentry-javascript/releases
How do you use Sentry?
Sentry Saas (sentry.io)
Which SDK are you using?
@sentry/nextjs
SDK Version
7.109.0
Framework Version
next 14.1.4
Link to Sentry event
No response
SDK Setup
No response
Steps to Reproduce
I'm deploying on Vercel which does not natively supply the SENTRY_RELEASE environment variable. It also doesn't have access to the Git repository for automatically identifying the GIT SHA hash.
I have a standard NextJS app configured according to the sentry docs.
I had a next.config.js file with the following configuration to pull the release from the environment. This matches the typescript type definitions for withSentryConfig.
I expected a config like this to build successfully:
/** @type {import('next').NextConfig} */
const nextConfig = {
poweredByHeader: false,
experimental: {
serverComponentsExternalPackages: ['@sentry/nextjs', '@sentry/node'],
}
};
module.exports = nextConfig;
const { withSentryConfig } = require('@sentry/nextjs');
module.exports = withSentryConfig(
module.exports,
{
org: 'my-org',
project: 'my-project',
release: process.env.NEXT_PUBLIC_SENTRY_RELEASE ?? process.env.NEXT_PUBLIC_VERCEL_GIT_COMMIT_SHA ?? 'development'
},
{
widenClientFileUpload: true,
transpileClientSDK: true,
tunnelRoute: '/trace',
hideSourceMaps: process.env.NEXT_PUBLIC_NODE_ENV === 'production'
}
);
I finally decided to look through the source for this repo and realised that release is an object, not a string (which the type definitions assert), and a config like this worked:
/** @type {import('next').NextConfig} */
const nextConfig = {
poweredByHeader: false,
experimental: {
serverComponentsExternalPackages: ['@sentry/nextjs', '@sentry/node'],
}
};
module.exports = nextConfig;
const { withSentryConfig } = require('@sentry/nextjs');
module.exports = withSentryConfig(
module.exports,
{
org: 'my org',
project: 'my project',
release: { //this doesn't match the types from the docs
name: process.env.NEXT_PUBLIC_SENTRY_RELEASE ?? process.env.NEXT_PUBLIC_VERCEL_GIT_COMMIT_SHA ?? 'development',
create: true,
finalise: true
}
},
{
widenClientFileUpload: true,
transpileClientSDK: true,
tunnelRoute: '/trace',
hideSourceMaps: process.env.NEXT_PUBLIC_NODE_ENV === 'production'
}
);
Expected Result
A successful build on Vercel.
Actual Result
The build fails with this error:
Running build in Washington, D.C., USA (East) – iad1
--
08:21:15.793 | Retrieving list of deployment files...
08:21:16.115 | Previous build cache not available
08:21:16.406 | Downloading 233 deployment files...
08:21:17.352 | Running "vercel build"
08:21:17.812 | Vercel CLI 33.6.2
08:21:18.129 | Warning: Detected "engines": { "node": ">=20.x" } in your `package.json` that will automatically upgrade when a new major Node.js Version is released. Learn More: http://vercel.link/node-version
08:21:18.141 | Running "install" command: `npm ci --include=dev --include=peer --include=optional --include=prod --no-audit --fund=false`...
08:22:23.655 |
08:22:23.655 | added 1753 packages in 1m
08:22:23.735 | Detected Next.js version: 14.1.4
08:22:23.735 | Running "next build --debug"
08:22:24.582 | Attention: Next.js now collects completely anonymous telemetry regarding usage.
08:22:24.582 | This information is used to shape Next.js' roadmap and prioritize features.
08:22:24.582 | You can learn more, including how to opt-out if you'd not like to participate in this anonymous program, by visiting the following URL:
08:22:24.582 | https://nextjs.org/telemetry
08:22:24.582 |
08:22:24.692 | ▲ Next.js 14.1.4
08:22:24.692 |
08:22:24.710 | Creating an optimized production build ...
08:22:55.382 | Failed to compile.
08:22:55.382 |
08:22:55.383 | Sentry CLI Plugin: Unable to determine version. Make sure to include `release` option or use the environment that supports auto-detection https://docs.sentry.io/cli/releases/#creating-releases
08:22:55.383 |
08:22:55.383 | Sentry CLI Plugin: Unable to determine version. Make sure to include `release` option or use the environment that supports auto-detection https://docs.sentry.io/cli/releases/#creating-releases
08:22:55.383 |
08:22:55.384 |
08:22:55.384 | > Build failed because of webpack errors
08:22:55.507 | Error: Command "next build --debug" exited with 1
Hi, which docs are you referring to?
This issue has gone three weeks without activity. In another week, I will close it.
But! If you comment or otherwise update it, I will reset the clock, and if you remove the label Waiting for: Community, I will leave it alone ... forever!
"A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀