Skip to content
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

[Nuxt] Investigate issue with server-side not building correctly (import and import() are added) #14514

Open
s1gr1d opened this issue Nov 27, 2024 · 0 comments
Assignees
Labels
Package: nuxt Issues related to the Sentry Nuxt SDK

Comments

@s1gr1d
Copy link
Member

s1gr1d commented Nov 27, 2024

--> scroll down to see the workaround for this issue

What is happening?

With the Nuxt rollup plugin (which is automatically added by the SDK), the content of sentry.server.config.ts is added to the server entry file (.output/server/index.mjs) and the rest of the server application (either nitro/nitro.mjs or runtime.mjs) is added via a dynamic import().

If it is correct, it should look something like this:

// CORRECT
// Note: file may have some imports and code related to debug IDs
Sentry.init({
  dsn: "..."
});

import('./chunks/nitro/nitro.mjs').then(function (n) { return n.r; });

async function default_sentryWrapped(...args) {
  const res = await import('./chunks/nitro/nitro.mjs').then(function (n) { return n.r; });
  return res.default.call(this, ...args);
}

export { default_sentryWrapped as default };

However, the build output sometimes looks like this:

// WRONG
import './chunks/nitro/nitro.mjs';    // <-- server file is added with `import`

/* ... same code as above */

This is a problem, because Sentry needs to be initialized before any other server-side code is loaded. With ES Modules, this can only happen by dynamically importing (with import()) the application to load it afterwards or using the --import flag. Sentry is not initialized correctly when there is another, regular import of the server-side code.

Debugging Process

The following things have been found out already:

  • the issue appears above nitropack 2.10.0 when using pnpm
  • the issue appears above nitropack 2.10.3 when using yarn
  • the issue disappears when deleting the .git folder (more on this below)
  • the issue disappears when deleting the contents of server/middleware
  • the issue disappears when commenting out this portion of nitropack in the node_modules (still needs some investigation if this happens continously)

Deleting .git

This is very strange, as there is no obvious connection to git. The files and folders listed below are the ones that affect the build output. If any of those are missing, the build output is correct again.

  • HEAD
  • objects (empty)
  • refs
    • heads
      • master

Workaround

The current workaround is overriding the version of nitropack. As the older version of nitropack is still including an old version of @vercel/nft, this override has to be added as well:

npm

"overrides": {
  "nitropack": "~2.9.7"
  "@vercel/nft": "^0.27.4"
}

yarn

"resolutions": {
  "nitropack": "~2.9.7"
  "@vercel/nft": "^0.27.4"
}

pnpm

"pnpm": {
  "overrides": {
    "nitropack": "~2.9.7"
    "@vercel/nft": "^0.27.4"
  }
}
@s1gr1d s1gr1d changed the title [Nuxt] Investigate issue with server-side not building correctly (adding import and import()) [Nuxt] Investigate issue with server-side not building correctly (import and import() are added) Nov 27, 2024
andreiborza added a commit to getsentry/sentry-wizard that referenced this issue Nov 28, 2024
Also adds automatic resolutions for @vercel/nft and ofetch.
See: getsentry/sentry-javascript#14514
andreiborza added a commit to getsentry/sentry-wizard that referenced this issue Nov 29, 2024
* feat(nuxt): Add downgrade path to nitro 2.9.7

Also adds automatic resolutions for @vercel/nft and ofetch.
See: getsentry/sentry-javascript#14514

* Update changelog

* Rewrite logic to just add overrides and not install deps

* Make clack utility for package overrides generic

* Pin nitropack version to ~2.9.7
@s1gr1d s1gr1d added the Package: nuxt Issues related to the Sentry Nuxt SDK label Jan 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Package: nuxt Issues related to the Sentry Nuxt SDK
Projects
None yet
Development

No branches or pull requests

2 participants