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

require('@grpc/grpc-js') returns undefined when using sentry configs on next-js app #6970

Closed
3 tasks done
geoport opened this issue Jan 30, 2023 · 3 comments · Fixed by #6979
Closed
3 tasks done

require('@grpc/grpc-js') returns undefined when using sentry configs on next-js app #6970

geoport opened this issue Jan 30, 2023 · 3 comments · Fixed by #6979
Labels
Package: nextjs Issues related to the Sentry Nextjs SDK Type: Bug

Comments

@geoport
Copy link

geoport commented Jan 30, 2023

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which package are you using?

@sentry/nextjs

SDK Version

7.34.0

Framework Version

Next 12.0.4

Link to Sentry event

No response

SDK Setup

// This file sets a custom webpack configuration to use your Next.js app
// with Sentry.
// https://nextjs.org/docs/api-reference/next.config.js/introduction
// https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/
const { withSentryConfig } = require('@sentry/nextjs');

/** @type {import('next').NextConfig} */
const nextConfig = {
	webpackDevMiddleware: (config) => {
		config.watchOptions = {
			poll: 1000,
			aggregateTimeout: 300,
		};
		return config;
	},
	reactStrictMode: true,
	env: {
		REACT_APP_DISABLE_WARNINGS: 1,
	},
	future: {
		webpack5: true, // by default, if you customize webpack config, they switch back to version 4.
		// Looks like backward compatibility approach.
	},
	webpack(config) {
		config.resolve.fallback = {
			...config.resolve.fallback, // if you miss it, all the other options in fallback, specified
			// by next.js will be dropped. Doesn't make much sense, but how it is
			fs: false, // the solution
		};

		return config;
	},
};

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
	hideSourcemaps: true,
	// For all available options, see:
	// https://github.com/getsentry/sentry-webpack-plugin#options.
};

module.exports = withSentryConfig(nextConfig, sentryWebpackPluginOptions);

Steps to Reproduce

I'm trying to import @grpc/grpc-js inside an API call. When I changed the next.config.js as I shared, require('@grpc/grpc-js') returns undefined.

Expected Result

Importing grpc package without problem

Actual Result

`
TypeError: Cannot read properties of undefined (reading 'loadPackageDefinition')
4 | const grpc = require('@grpc/grpc-js');
5 | const pkgDefs = importProto('proto/goquake.proto');

6 | const goQuakeProto = grpc.loadPackageDefinition(pkgDefs).GoQuake;
`

@HazAT HazAT added the Package: nextjs Issues related to the Sentry Nextjs SDK label Jan 30, 2023
@joshuajaco
Copy link
Contributor

joshuajaco commented Jan 30, 2023

This issue is also related to using rollup-plugin-commonjs (See: #6943)

const grpc = require('@grpc/grpc-js');

Will be transformed to:

import grpc from '@grpc/grpc-js';

Which is not correct, since @grpc/grpc-js does not have a default export.

@lforst
Copy link
Member

lforst commented Feb 1, 2023

Hi, we just released an update that should fix this problem. https://github.com/getsentry/sentry-javascript/releases/tag/7.35.0

Let me know if upgrading the SDK fixes this issue for you!

@geoport
Copy link
Author

geoport commented Feb 1, 2023 via email

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

Successfully merging a pull request may close this issue.

4 participants