Closed panghaoyuan closed 2 years ago
i am sure this bug is caused here But I don't know how to fixed it
/**
* Combine default and user-provided SentryWebpackPlugin options, accounting for whether we're building server files or
* client files.
*
* @param buildContext Nexjs-provided data about the current build
* @param userPluginOptions User-provided SentryWebpackPlugin options
* @returns Final set of combined options
*/
export function getWebpackPluginOptions(
buildContext: BuildContext,
userPluginOptions: Partial<SentryWebpackPluginOptions>,
): SentryWebpackPluginOptions {
const { buildId, isServer, webpack, config: userNextConfig, dev: isDev, dir: projectDir } = buildContext;
const distDir = userNextConfig.distDir ?? '.next'; // `.next` is the default directory
const isWebpack5 = webpack.version.startsWith('5');
const isServerless = userNextConfig.target === 'experimental-serverless-trace';
const hasSentryProperties = fs.existsSync(path.resolve(projectDir, 'sentry.properties'));
const urlPrefix = userNextConfig.basePath ? `~${userNextConfig.basePath}/_next` : '~/_next';
const serverInclude = isServerless
? [{ paths: [`${distDir}/serverless/`], urlPrefix: `${urlPrefix}/serverless` }]
: [{ paths: [`${distDir}/server/pages/`], urlPrefix: `${urlPrefix}/server/pages` }].concat(
isWebpack5 ? [{ paths: [`${distDir}/server/chunks/`], urlPrefix: `${urlPrefix}/server/chunks` }] : [],
);
const clientInclude = userNextConfig.sentry?.widenClientFileUpload
? [{ paths: [`${distDir}/static/chunks`], urlPrefix: `${urlPrefix}/static/chunks` }]
: [{ paths: [`${distDir}/static/chunks/pages`], urlPrefix: `${urlPrefix}/static/chunks/pages` }];
const defaultPluginOptions = dropUndefinedKeys({
include: isServer ? serverInclude : clientInclude,
ignore:
isServer || !userNextConfig.sentry?.widenClientFileUpload
? []
: // Widening the upload scope is necessarily going to lead to us uploading files we don't need to (ones which
// don't include any user code). In order to lessen that where we can, exclude the internal nextjs files we know
// will be there.
['framework-*', 'framework.*', 'main-*', 'polyfills-*', 'webpack-*'],
url: process.env.SENTRY_URL,
org: process.env.SENTRY_ORG,
project: process.env.SENTRY_PROJECT,
authToken: process.env.SENTRY_AUTH_TOKEN,
configFile: hasSentryProperties ? 'sentry.properties' : undefined,
stripPrefix: ['webpack://_N_E/'],
urlPrefix,
entries: (entryPointName: string) => shouldAddSentryToEntryPoint(entryPointName, isServer),
release: getSentryRelease(buildId),
dryRun: isDev,
});
checkWebpackPluginOverrides(defaultPluginOptions, userPluginOptions);
return { ...defaultPluginOptions, ...userPluginOptions };
}
here has the same bug 4835
Hi @panghaoyuan, we do not recommend overriding the urlPrefix
option in the next SDK (see here). Can you share with us what you are trying to achieve?
Also, can you check if next's basePath option better fit your use case? The Sentry next.js SDK sets the urlPrefix
option by looking at next's basePath
setting. You can find the logic for that here: https://github.com/getsentry/sentry-javascript/blob/c518955b774e5bbc36e7f1a22410703469911a2a/packages/nextjs/src/config/webpack.ts#L290
@lforst
I think i set bastPath is not good.
my siteUrl is www.xxx.com
if i set basePath
. my siteUrl will be change.
such as
www.xxx.com
=> www.xxx.com/[basePath]
www.xxx.com/homePage
=> www.xxx.com/[basePath]/homePage
if i am not set urlPrefix. sentry ARTIFACT is ~/_next/server/chunks/1082.js
my sourcemap is useless in sentry.
i set urlPrefix
in next.config.js
because I used CDN to deal with static resources.
such as https://cdn_site/yuyang.m/_next/static/chunks/pages/_app-269c4298b3da0c34.js
yuyang.m
is my project name
if my senry ARTIFACT is ~/yuyang.m/_next/server/chunks/1082.js
. sentry sourcemap is worked.
I change next config. JS
solves this problem,but i think it not a good idea.
const SentryWebpackPluginOptions = {
include: [
{ paths: ['.next/static/'], urlPrefix: '~/yuyang.m/_next/static' },
{
paths: ['.next/server/'],
urlPrefix: '~/yuyang.m/_next/server',
},
],
silent: true,
ignore: ['node_modules'],
};
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 🥀
If this issue is solved it would fix https://github.com/getsentry/sentry-javascript/issues/4174 which is affecting me too
Is there an existing issue for this?
How do you use Sentry?
Self-hosted/on-premise
Which package are you using?
@sentry/nextjs
SDK Version
6.19.7
Framework Version
No response
Link to Sentry event
No response
Steps to Reproduce
// next.config.js
Expected Result
The file path uploaded to the archive must start with ~/yuyang.m/_next.
Actual Result
The file path uploaded to the archive starts with ~/_next.