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

[nextjs] Default imports become undefined when using the SDK #8019

Closed
3 tasks done
ekeric13 opened this issue May 3, 2023 · 8 comments
Closed
3 tasks done

[nextjs] Default imports become undefined when using the SDK #8019

ekeric13 opened this issue May 3, 2023 · 8 comments
Labels
Package: nextjs Issues related to the Sentry Nextjs SDK Type: Bug

Comments

@ekeric13
Copy link

ekeric13 commented May 3, 2023

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/nextjs

SDK Version

7.50.0

Framework Version

18.2.0

Link to Sentry event

No response

SDK Setup

server

Sentry.init({
  dsn: '__DSN__',

  // Adjust this value in production, or use tracesSampler for greater control
  tracesSampleRate: 1,

  // Setting this option to true will print useful information to the console while you're setting up Sentry.
  debug: false,
});

client:

Sentry.init({
  dsn: '__DSN__',

  // Adjust this value in production, or use tracesSampler for greater control
  tracesSampleRate: 1,

  // Setting this option to true will print useful information to the console while you're setting up Sentry.
  debug: false,

  replaysOnErrorSampleRate: 1.0,

  // This sets the sample rate to be 10%. You may want this to be 100% while
  // in development and sample at a lower rate in production
  replaysSessionSampleRate: 0.1,

  // You can remove this option if you're not planning to use the Sentry Session Replay feature:
  integrations: [
    new Sentry.Replay({
      // Additional Replay configuration goes in here, for example:
      maskAllText: true,
      blockAllMedia: true,
    }),
  ],
});

Steps to Reproduce

When using default imports/exports, somehow the module becomes undefined:

// redispool.ts
const redisPool = new RedisPool(redisUrl);
export default redisPool;

// index.ts
import redisPool from './redispool';

console.log({redisPool}) // redisPool: undefined

This is my next.config.js:

const sentryWebpackConfig = {
  // For all available options, see:
  // https://github.com/getsentry/sentry-webpack-plugin#options

  // Suppresses source map uploading logs during build
  silent: true,

  org: 'my-org',
  project: 'javascript-nextjs',
};

const sentryConfig = {
  // For all available options, see:
  // https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/

  // Hides source maps from generated client bundles
  hideSourceMaps: true,

  // Automatically tree-shake Sentry logger statements to reduce bundle size
  disableLogger: true,
};

const isProduction = process.env.NODE_ENV === 'production';

module.exports = isProduction
  ? withSentryConfig(nextConfig, sentryWebpackConfig, sentryConfig)
  : nextConfig;

Expected Result

Changing to use named exports fixes this issue:

// redispool.ts
export const redisPool = new RedisPool(redisUrl);

// index.ts
import { redisPool } from './redispool';

console.log({redisPool}) // redisPool: RedisPool

I expected this to work without using named exports though.

Actual Result

as mentioned currently the above logs undefined.

Really confused why this is happening. If I don't use sentry default exports work perfectly fine.
Does sentry expect all imports to be named?

@lforst
Copy link
Member

lforst commented May 3, 2023

I assume you're importing redisPool from a file inside pages/ or app/?

@lforst lforst added Status: Untriaged Package: nextjs Issues related to the Sentry Nextjs SDK and removed Status: Untriaged labels May 3, 2023
@lforst lforst changed the title [nextjs] When adding sentry modules are getting imported as undefined [nextjs] Default imports become undefined when using the SDK May 3, 2023
@ekeric13
Copy link
Author

ekeric13 commented May 4, 2023

Yeah. Specifically I am doing:

// src/pages/api/auth/[...nextauth].ts
import { redisPool } from './redispool';

So insides the pages directory.

@github-actions
Copy link
Contributor

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 Status: Backlog or Status: In Progress, I will leave it alone ... forever!


"A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀

@ekeric13
Copy link
Author

Waiting for a response still

@lforst
Copy link
Member

lforst commented May 26, 2023

I am wondering, since the code you shared is:

// src/pages/api/auth/[...nextauth].ts
import { redisPool } from './redispool';
  • Do you have a /api/auth/redispool route?
  • Another question: Are you using the edge runtime?

@github-actions
Copy link
Contributor

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 Status: Backlog or Status: In Progress, I will leave it alone ... forever!


"A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀

@github-actions
Copy link
Contributor

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 Status: Backlog or Status: In Progress, I will leave it alone ... forever!


"A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀

@lforst
Copy link
Member

lforst commented Aug 17, 2023

This should be fixed in the newest version of the SDK. Feel free to ping us if this is not the case for you!

@lforst lforst closed this as completed Aug 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Package: nextjs Issues related to the Sentry Nextjs SDK Type: Bug
Projects
None yet
Development

No branches or pull requests

2 participants