Search code examples
next.jssentry

Can not run server after add sentry to nextjs project


I prefer the docs from https://docs.sentry.io/platforms/javascript/guides/nextjs to add @sentry/nextjs to my project. Then i added their config to my next.config.js

const { withSentryConfig } = require('@sentry/nextjs');
// module.exports = withBundleAnalyzer(nextConfig)
module.exports = {
}

const moduleExports = module.exports

const SentryWebpackPluginOptions = {
  // Additional config options for the Sentry Webpack plugin. Keep in mind that
  // the following options are set automatically, and overriding them is not
  // recommended:
  //   release, url, org, project, authToken, configFile, stripPrefix,
  //   urlPrefix, include, ignore

  silent: true, // Suppresses all logs
  // For all available options, see:
  // https://github.com/getsentry/sentry-webpack-plugin#options.
};

// Make sure adding Sentry options is the last code to run before exporting, to
// ensure that your source maps include changes from all other Webpack plugins
module.exports = withSentryConfig(moduleExports, SentryWebpackPluginOptions);

Everythings seem to be fine before i run my server by yarn dev and got this error

Error: Could not find a valid build in the 'C:\Users\DELL\Desktop\ws-or\fjob-frontend\.next' directory! Try building your app with 'next build' before starting the server.
    at Server.readBuildId (C:\Users\DELL\Desktop\ws-or\fjob-frontend\node_modules\next\dist\next-server\server\next-server.js:137:355)
    at new Server (C:\Users\DELL\Desktop\ws-or\fjob-frontend\node_modules\next\dist\next-server\server\next-server.js:3:120)
    at Function.createServer [as default] (C:\Users\DELL\Desktop\ws-or\fjob-frontend\node_modules\next\dist\server\next.js:2:638)
    at Object.instrumentServer (C:\Users\DELL\Desktop\ws-or\fjob-frontend\node_modules\@sentry\nextjs\dist\utils\instrumentServer.js:42:67)
    at Object.<anonymous> (C:\Users\DELL\Desktop\ws-or\fjob-frontend\node_modules\@sentry\nextjs\dist\index.server.js:56:20)
    at Module._compile (internal/modules/cjs/loader.js:1068:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1097:10)
    at Module.load (internal/modules/cjs/loader.js:933:32)
    at Function.Module._load (internal/modules/cjs/loader.js:774:14)
    at Module.require (internal/modules/cjs/loader.js:957:19)
(node:4084) Warning: Accessing non-existent property 'default' of module exports inside circular dependency     
(Use `node --trace-warnings ...` to show where the warning was created)
(node:4084) Warning: Accessing non-existent property 'target' of module exports inside circular dependency      
(node:4084) Warning: Accessing non-existent property 'amp' of module exports inside circular dependency
(node:4084) Warning: Accessing non-existent property 'experimental' of module exports inside circular dependency
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

After days of research i can not resolve this error. My nextjs config is empty and i do not think this is the problem of next. If i remove the sentry config, i can start my server like normal. Any idea?


Solution

  • The solution to this problem is, upgrade next.js to >= 10.0.8 github.com/getsentry/sentry-javascript/issues/3724