Skip to content

Conversation

@0ubbe
Copy link
Contributor

@0ubbe 0ubbe commented Jun 6, 2025

Changes πŸ—οΈ

We were getting the following warnings in the console when running the local server:

 ⚠ ./node_modules/.pnpm/@sentry+node@9.26.0/node_modules/@sentry/node/build/cjs/sdk
Package import-in-the-middle can't be external
The request import-in-the-middle matches serverExternalPackages (or the default list).
The request could not be resolved by Node.js from the project directory.
Packages that should be external need to be installed in the project directory, so they can be resolved from the output files.
Try to install it into the project directory by running npm install import-in-the-middle from the project directory.

Why were the warnings happening?

The Sentry SDK for Next.js tries to hook into Node.js internals using packages like import-in-the-middle and require-in-the-middle. When Sentry is imported at the top level on a file (even if not enabled), it tries to load these dependencies... If they are not installed, then we get these warnings...

Why does installing the packages fix it?

By installing import-in-the-middle and require-in-the-middle as dev dependencies, Sentry finds them and the warnings disappear. This is a safe workaround for local/dev, and does not affect production.

Loading Sentry conditionally

One way to avoid these warnings ⚠️ is by loading Sentry conditionally. That is the approach I took in an earlier PR. However I realised that it would have to apply to any file importing Sentry:

import * as Sentry from "@sentry/nextjs";

which would end quite messy and affecting a lot of files. I realised installing the packages is just simpler ( they won't in the bundle or affect page load ) and using enabled in the Sentry initialisation is also cleaner.

Checklist πŸ“‹

For code changes:

  • I have clearly listed my changes in the PR description
  • I have made a test plan
  • I have tested my changes according to the test plan:
    • There are not Sentry warnings when running the local dev server ( with or without --turbo )
    • Sentry still reports issues in production or staging ( but not locally )

@0ubbe 0ubbe requested a review from a team as a code owner June 6, 2025 11:41
@0ubbe 0ubbe requested review from Bentlybro and majdyz and removed request for a team June 6, 2025 11:41
@github-project-automation github-project-automation bot moved this to πŸ†• Needs initial review in AutoGPT development kanban Jun 6, 2025
@netlify
Copy link

netlify bot commented Jun 6, 2025

βœ… Deploy Preview for auto-gpt-docs-dev canceled.

Name Link
πŸ”¨ Latest commit 462a917
πŸ” Latest deploy log https://app.netlify.com/projects/auto-gpt-docs-dev/deploys/6842fe60378ca600085b1b30

@qodo-code-review
Copy link

PR Reviewer Guide πŸ”

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 2 πŸ”΅πŸ”΅βšͺβšͺβšͺ
πŸ§ͺΒ No relevant tests
πŸ”’Β No security concerns identified
⚑ Recommended focus areas for review

Conditional Logic

The PR changes Sentry initialization from a conditional import to using the 'enabled' flag. Verify that this approach correctly prevents Sentry from initializing in non-production or non-cloud environments.

const isProductionCloud =
  process.env.NODE_ENV === "production" && getBehaveAs() === BehaveAs.CLOUD;

Sentry.init({
  dsn: "https://fe4e4aa4a283391808a5da396da20159@o4505260022104064.ingest.us.sentry.io/4507946746380288",

  environment: getEnvironmentStr(),

  enabled: isProductionCloud,

@deepsource-io
Copy link

deepsource-io bot commented Jun 6, 2025

Here's the code health analysis summary for commits a5ff8e8..462a917. View details on DeepSourceΒ β†—.

Analysis Summary

AnalyzerStatusSummaryLink
DeepSource JavaScript LogoJavaScriptβœ…Β Success
❗ 1 occurence introduced
🎯 1 occurence resolved
View CheckΒ β†—
DeepSource Python LogoPythonβœ…Β SuccessView CheckΒ β†—

πŸ’‘ If you’re a repository administrator, you can configure the quality gates from the settings.

@netlify
Copy link

netlify bot commented Jun 6, 2025

βœ… Deploy Preview for auto-gpt-docs ready!

Name Link
πŸ”¨ Latest commit ede3f80
πŸ” Latest deploy log https://app.netlify.com/projects/auto-gpt-docs/deploys/6842d3f2a4a6bd000837b93d
😎 Deploy Preview https://deploy-preview-10125--auto-gpt-docs.netlify.app
πŸ“± Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@0ubbe
Copy link
Contributor Author

0ubbe commented Jun 6, 2025

@Pwuts Sentry changes separate as we spoke πŸ‘πŸ½ πŸ’―

@0ubbe 0ubbe requested a review from Pwuts June 6, 2025 11:42
@netlify
Copy link

netlify bot commented Jun 6, 2025

βœ… Deploy Preview for auto-gpt-docs canceled.

Name Link
πŸ”¨ Latest commit 462a917
πŸ” Latest deploy log https://app.netlify.com/projects/auto-gpt-docs/deploys/6842fe60b8170800085bd6d1

@0ubbe 0ubbe enabled auto-merge June 6, 2025 14:42
Copy link
Contributor

@Swiftyos Swiftyos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work, thank you πŸ™

@0ubbe 0ubbe added this pull request to the merge queue Jun 10, 2025
@github-project-automation github-project-automation bot moved this from πŸ†• Needs initial review to πŸ‘πŸΌ Mergeable in AutoGPT development kanban Jun 10, 2025
Merged via the queue into Significant-Gravitas:dev with commit 2f16511 Jun 10, 2025
25 checks passed
@0ubbe 0ubbe deleted the fix/sentry-local-warnings branch June 10, 2025 10:35
@github-project-automation github-project-automation bot moved this from πŸ‘πŸΌ Mergeable to βœ… Done in AutoGPT development kanban Jun 10, 2025
@github-project-automation github-project-automation bot moved this to Done in Frontend Jun 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: βœ… Done
Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants