getsentry / sentry-webpack-plugin

Repo moved to https://github.com/getsentry/sentry-javascript-bundler-plugins. Please open any issues/PRs there.
MIT License
662 stars 116 forks source link

[nextjs] When adding sentry modules are getting imported as undefined #442

Closed ekeric13 closed 1 year ago

ekeric13 commented 1 year ago

Environment

What version are you running? Etc.

"@sentry/nextjs": "^7.50.0"

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}) // undefined

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

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

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;
ekeric13 commented 1 year ago

Closing in favor of opening the issue in the main repo:

https://github.com/getsentry/sentry-javascript/issues/8019