将哨兵添加到 nextjs 项目后无法 运行 服务器

Can not run server after add sentry to nextjs project

我更喜欢 https://docs.sentry.io/platforms/javascript/guides/nextjs 的文档将 @sentry/nextjs 添加到我的项目中。然后我将他们的配置添加到我的 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);

在我 运行 我的服务器由 yarn dev 得到这个错误之前一切似乎都很好

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.

经过几天的研究,我无法解决这个错误。我的 nextjs 配置是空的,我不认为这是 next 的问题。如果我删除哨兵配置,我可以像往常一样启动我的服务器。有什么想法吗?

这个问题的解决方法是,将next.js升级到>=10.0.8github。com/getsentry/sentry-javascript/issues/3724

为我升级Next.js版本到最新作品

运行升级到最新版本

npm install next@latest or yarn add next@latest

查看here了解更多信息