-
-
Notifications
You must be signed in to change notification settings - Fork 344
Sourcemaps not working (Metro bundler) #3244
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
Comments
Hey @mikevercoelen, thanks for the detailled report, we'll look into this and follow up here. Please be aware that due to vacations and our hackweek next week, we will likely be a bit slower to respond to and resolve issues. |
Just flagging that this could also potentially be related to an issue raised here expo/sentry-expo#364 in which source maps are unable to be uploaded to Sentry since Expo v49. I've added some excepts from our Expo Application Service build to that issue which includes this output from the sentry-cli. |
@kahest , any ability to prioritize this would be appreciated. I imagine several other teams are also heavily impacted currently. |
@mikevercoelen Thank you for the detailed message and the code samples. It looks like you are only uploading the bundle file but not its source map. const bundlePath = path.resolve(DIST_PATH, bundleFileName); You can add the map file or just pass the await cli.uploadSourceMaps(version, {
include: [bundlePath, bundleMapPath],
}); |
@Kudo Thank you for the link to the changes we will update |
The original issue is about manual source maps upload, solution here. The original issue is not related to the expo/sentry-expo#364. |
oh no sorry for posting to wrong issue and thanks @krystofwoldrich for helping for both two issues 👏 |
@krystofwoldrich Applied the fix, verified it's uploading the source maps and bundle, still no working source maps, all events are still referring to scrambled source code. |
@mikevercoelen Thank you for the message, Have you checked that the events in Sentry have the same release and dist and the uploaded artifacts? If your events have await cli.uploadSourceMaps(version, {
include: [bundlePath],
dist: 'dist_value',
}); |
is it planned to add docs about web sourcemaps and maybe a guide how to streamline web deployments? 🤔 |
Since there are no new reactions to #3244 (comment) I'm closing this issue. |
Hello the sourcemap is still not being uploaded. Can we have instruction on how to upload the sourcemap with sentry? On older version of expo I didn't have this problem. It has now been a few months i'm using expo without sourcemaps |
@felix-lambert Could you please open a new issue with details of our setup (Expo version, RN version, Sentry SDK version...)? |
@krystofwoldrich Hello I'm using sentry-expo. Do I still need to open an issue here? Also like to mention that the sourcemap seems to upload well on the web app version but not on android or ios |
@felix-lambert We are working on #3262, so feel free to open the issue here. |
Here is a tested solution to fix sourcemaps on Web for expo@49. Import this file (name it /*
We inject bundle id and release id as would Sentry bunder plugin do
cf https://github.com/getsentry/sentry-javascript-bundler-plugins/blob/main/packages/bundler-plugin-core/src/index.ts
and https://github.com/getsentry/sentry-javascript-bundler-plugins/blob/main/packages/bundler-plugin-core/src/utils.ts
Code may be interpreted by Sentry to get bundle id and release id so we must keep original code as much as possible.
Only exceptions are replacing the followings with pure literals:
- process.env.EXPO_PUBLIC_SENTRY_DEBUG_ID
- process.env.EXPO_PUBLIC_SENTRY_DEBUG_ID_IDENTIFIER
- process.env.EXPO_PUBLIC_SENTRY_REALEASE_ID
*/
!(function () {
try {
var e =
'undefined' != typeof window
? window
'undefined' != typeof global
? global
'undefined' != typeof self
? self
: {},
t = new Error().stack;
t &&
((e._sentryDebugIds = e._sentryDebugIds || {}),
(e._sentryDebugIds[t] = process.env.EXPO_PUBLIC_SENTRY_DEBUG_ID),
(e._sentryDebugIdIdentifier = process.env.EXPO_PUBLIC_SENTRY_DEBUG_ID_IDENTIFIER));
} catch (e) {}
})();
var _global =
'undefined' !== typeof window
? window
: 'undefined' !== typeof global
? global
: 'undefined' !== typeof self
? self
: {};
_global.SENTRY_RELEASE = {
id: process.env.EXPO_PUBLIC_SENTRY_REALEASE_ID,
}; Then build your app with a script like this (ESM so name it import { spawn } from 'node:child_process';
import * as crypto from 'node:crypto';
import * as fs from 'node:fs';
import * as path from 'node:path';
import SentryCli from '@sentry/cli';
import chalk from 'chalk';
import { z } from 'zod';
const DIST_PATH = './dist';
const releaseId = new Date().toISOString();
const debugId = crypto.randomUUID();
const log = (s: string) => {
console.log('\n', chalk.yellowBright(s));
};
log('Setting Sentry env vars...');
process.env.EXPO_PUBLIC_SENTRY_DEBUG_ID = debugId;
process.env.EXPO_PUBLIC_SENTRY_DEBUG_ID_IDENTIFIER = `sentry-dbid-${debugId}`;
process.env.EXPO_PUBLIC_SENTRY_REALEASE_ID = releaseId;
log('Exporting for Web...');
const shell = spawn(
process.platform === 'win32' ? 'yarn.cmd' : 'yarn',
'expo export -p web --dump-sourcemap'.split(' '),
{
stdio: 'inherit',
},
);
await new Promise((resolve: (code: number, signal: NodeJS.Signals) => void) => {
shell.on('close', resolve);
});
log('Removing useless files...');
const manifestZod = z
.object({
version: z.number(),
bundler: z.literal('metro'),
fileMetadata: z
.object({
web: z
.object({
bundle: z.string().endsWith('.js'),
assets: z.array(
z
.object({
path: z.string().startsWith('assets'),
ext: z.enum(['png', 'jpg', 'ttf']),
})
.strict(),
),
})
.strict(),
})
.strict(),
})
.strict();
const manifest = manifestZod.parse(
JSON.parse(fs.readFileSync(path.join(DIST_PATH, 'metadata.json'), 'utf-8')),
);
fs.unlinkSync(path.join(DIST_PATH, 'metadata.json'));
fs.unlinkSync(path.join(DIST_PATH, 'debug.html'));
manifest.fileMetadata.web.assets.forEach((asset) => {
fs.unlinkSync(path.join(DIST_PATH, asset.path));
});
log('Uploading source maps...');
const cli = new SentryCli(null, { org: 'your_sentry_org', project: 'your_sentry_project' }).releases;
await cli.new(releaseId);
await cli.uploadSourceMaps(releaseId, { include: [DIST_PATH] });
await cli.finalize(releaseId);
log('Removing source maps...');
fs.unlinkSync(path.join(DIST_PATH, manifest.fileMetadata.web.bundle.replace(/\.js$/u, '.map')));
log(`Version ${releaseId} of app Web ready to deploy!`); |
@jer-sen How do you guys initialize Sentry? By using If so what are the Also running |
@mikevercoelen on Web we use You are right for Note also that it's only working for expo@49 (cf https://docs.expo.dev/guides/environment-variables/) |
We're at the 3rd attempt right now to get Sentry sourcemaps working for using
expo export --platform
web, which is running Metro bundler for web.The screenshot below is a result from running
sentry-cli sourcemaps explain <eventId>
This is our setup:
package.json > scripts
Our CI/CD triggers
npm run exportWeb && npm run uploadWebSourceMaps
This is
uploadWebSourceMaps.js
This is
utils/sentry/cli.js
Any help / advise would be great.
The text was updated successfully, but these errors were encountered: