-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TypeError: withSentryConfig is not a function #5511
Comments
Hi, @coreypett33. I've tried and can't replicate this behavior. Can you please provide a small repro app? |
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 label it "A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀 |
I immediately hit this error using the sentry wizard. Something is broken with it. |
For future people who encounter this error: I fixed this by converting my next.config.js file into Then export the config like so: The issue seems to be that the Sentry configuration requires that you do a module import, which isn't supported by a regular next.config.js. See the next.js docs on the config file here. |
this didnt fix the issue for me |
I'm trying to upgrade from 7.30.0 to 7.43.0 but when I try to upgrade, it throws this error while building. |
We need reproduction in order to fix this. |
@prateekjain98 and I managed to fix this by deleting our |
@lforst Reproduction here: https://github.com/luhmann/nextjs-with-sentry-not-function-repro The underlying problem seems to be that new versions This is what I did to get to the code in the repo linked above:
If there is a new way required to get this capability please point me to the required documentation. I checked the manual setup docs and could not find anything. My full
|
@luhmann In your repro you pass in an object, and try to call the return value. This will fail since you cannot call an object. Also I think your error is slightly different than what was reported in this issue so we still lack repro. |
@lforst Thank you for your help, this indeed solved the problem. And you are correct this is a different problem, got a bit lost in the Github issues. Sorry about that.
The interface of Thank you again for your speedy reply. |
@luhmann no worries! The changes around |
Everything is running fine, but on a certain page, I imported Next.js config (import config from 'next.config'), then an error occurred: TypeError: withSentryConfig is not a function. |
@Rizki36 Importing withConfig from a page is not a supported use-case. Why are you doing that? |
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 label it "A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀 |
@lforst, I'm getting the same error ("TypeError: withSentryConfig is not a function") after using the wizard. Admittedly, I'm a webpack and NextJS newbie, but nothing stands out as being obviously wrong and I've double-checked with the docs https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/#extend-your-nextjs-configuration. My const path = require('path');
const { withSentryConfig } = require('@sentry/nextjs');
const { i18n } = require('./next-i18next.config');
module.exports = {
swcMinify: true,
experimental: {
outputStandalone: true,
},
trailingSlash: true,
reactStrictMode: true,
env: {
API_KEY: process.env.API_KEY,
},
webpack: (config) => {
config.resolve.fallback = { fs: false, os: false };
return config;
},
webpackDevMiddleware: (config) => {
config.watchOptions = {
poll: 1000,
aggregateTimeout: 300,
};
return config;
},
sassOptions: {
includePaths: [path.join(__dirname, 'styles')],
prependData: `@import "src/styles/mixins/mixins.scss";`,
},
eslint: {
dirs: ['src'],
},
images: {
deviceSizes: [640, 750, 828, 1080, 1200, 1920],
domains: [
<redacted>
],
},
i18n,
async headers() {
return [
{
source: '/(.*)',
headers: [
{
key: 'Content-Security-Policy',
value: 'frame-ancestors <redacted>;',
},
{
key: 'X-Frame-Options',
value: 'ALLOW-FROM <redacted>;',
},
{
key: 'Strict-Transport-Security',
value: 'max-age=31536000;',
},
],
},
];
},
};
module.exports = withSentryConfig(
module.exports,
{
// For all available options, see:
// https://github.com/getsentry/sentry-webpack-plugin#options
// Suppresses source map uploading logs during build
silent: true,
org: <redacted>,
project: <redacted>,
},
{
// For all available options, see:
// https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/
// Upload a larger set of source maps for prettier stack traces (increases build time)
widenClientFileUpload: true,
// Transpiles SDK to be compatible with IE11 (increases bundle size)
transpileClientSDK: true,
// Routes browser requests to Sentry through a Next.js rewrite to circumvent ad-blockers (increases server load)
tunnelRoute: '/monitoring',
// Hides source maps from generated client bundles
hideSourceMaps: true,
// Automatically tree-shake Sentry logger statements to reduce bundle size
disableLogger: true,
}
); |
@ianbayne What version of the Next.js SDK are you on? |
Thanks for the speedy response, @lforst! Here are the relevant dependency versions from my "@sentry/nextjs": "^7.51.2",
"next": "^12.1.6", Please let me know if there's any other information you need. |
@ianbayne can you try wiping your node_modules and reinstalling them? Thanks. |
Thanks, @lforst. Unfortunately even after doing so I still get the same error. Interestingly I notice my local Next server is showing a different error than the browser:
The content of my import { NextRequest, NextResponse } from 'next/server';
// Regex to check whether something has an extension, e.g. .jpg
const PUBLIC_FILE = /\.(.*)$/;
const countries = ['en-US', 'fr', 'de', 'it'];
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
export const middleware = (request: NextRequest) => {
const { nextUrl, headers } = request;
const url = nextUrl.clone();
const language =
headers
.get('accept-language')
?.split(',')?.[0]
.split('-')?.[0]
.toLowerCase() || 'en-US';
try {
// Early return if it is a public file such as an image
if (PUBLIC_FILE.test(nextUrl.pathname)) {
return undefined;
}
// Early return if this is an api route
if (nextUrl.pathname.includes('/api')) {
return undefined;
}
if (nextUrl.pathname === '/' && nextUrl.locale === '__default') {
url.pathname = countries.includes(language) ? `/${language}` : `/en-US`;
return NextResponse.redirect(url);
}
// If everything else falls through continue on with response as normal
return undefined;
} catch (error) {
console.log(error);
}
}; and the file where // src/pages/_document.tsx
import Document, {
Html,
Head,
Main,
NextScript,
DocumentContext,
DocumentInitialProps,
} from 'next/document';
class MyDocument extends Document {
static async getInitialProps(
ctx: DocumentContext
): Promise<DocumentInitialProps> {
const initialProps = await Document.getInitialProps(ctx);
return initialProps;
}
render(): JSX.Element {
return (
<Html>
<Head />
<body>
<Main />
<NextScript />
</body>
</Html>
);
}
}
export default MyDocument; I've looked through the Sentry GitHub issues on |
@ianbayne Can you try migrating your |
Thanks for the response, @lforst. I was actually able to resolve the issue I was having by doing both of the following:
Thanks again for all your help! |
@ianbayne Thanks for giving an update! We didn't consider that people may import the next config from components. I think this is something we should fix (by exporting the function on the clientside but making it a noop). As for the middleware. I actually wanna discourage you from setting |
Thanks, @lforst. Despite the error message above, my middleware file is indeed located at What's more, removing Thanks again! |
Is there an existing issue for this?
How do you use Sentry?
Sentry Saas (sentry.io)
Which package are you using?
@sentry/nextjs
SDK Version
7.8.1
Framework Version
"react": "^17.0.2", "next": "^11.1.2",
Link to Sentry event
No response
Steps to Reproduce
https://docs.sentry.io/platforms/javascript/guides/nextjs/
yarn dev
Expected Result
App should start
Actual Result
localhost:3001
shows the following error in chrome.Terminal does not show the error.
The text was updated successfully, but these errors were encountered: