visit
Uh oh, so “name of undefined”, oh I know, an
If check
is all I need.where again? — In:chatModule-322816772254.js in h.e.uploadFile at line 1:27468.
debug:true
in your browserify optionsgulp-sourcemaps
& initialise the same before minifying the codevar sourcemaps = require('gulp-sourcemaps');
browserify(path, {
paths: ['./node_modules'],
// Enables source maps
debug: true,
})
// Any babel config may come here
// ---
// Initialises & writes source maps
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(uglify())
.pipe(sourcemaps.write('.'))
// Used to export generated minified files & source maps
.pipe(gulp.dest('./web/js'));
At this point we have our minified files & source maps generated in the
/web/js
folder like /web/js/file.min.js
& /web/js/file.js
which are hosted as //{your_domain}/js/file.min.js
& //{your_domain}/js/file.js
respectively.Here’s a script which uses
sentry-cli
to upload the javascript files from a folder to sentry & remove the source maps files post that:// Credit: //github.com/supriya-raj
var spawn = require('child_process').spawnSync;
var sentryHost, sentryAuthToken, sentryProjectName, sentryOrg, release;
/*
Change based on your requirement:
sourceMapsPath: relative path to the folder that contains your minified scripts & source maps
jsUrlPrefix: ~ (tilde) -> Acts as your domain. Ex: if the source maps are hosted on domain.com/js/file.js.map
this should be '~/js'
release: source maps will be pushed under this release name
sentryConfig: {
org: 'dummyorg'
project: 'my-js-project'
host: '//sentry9.dummyorg.com'
auth_token: ~
}
^ Example configuration for the sentry url: //sentry9.dummyorg.com/dummyorg/my-js-project
*/
var sourceMapsPath = 'web/js';
var jsUrlPrefix = '~/js';
var sentryConfig = require('./sentry-config.js')
if(sentryConfig) {
sentryHost = sentryConfig['host'];
sentryProjectName = sentryConfig['project'];
sentryOrg = sentryConfig['org'];
sentryAuthToken = sentryConfig['auth_token'];
}
release = process.env.COMMIT_HASH;
if (!sentryAuthToken || !sentryHost || !sentryProjectName || !sentryOrg) {
console.log(console.log('[Error] One or more config parameters required for source map upload are missing!'));
process.exit(1);
}
if (!release) {
console.log(console.log('[Error] Environment variable COMMIT_HASH does not exist!'));
process.exit(1);
}
spawn(
'./node_modules/.bin/sentry-cli',
[
'--auth-token', sentryAuthToken, '--url', sentryHost, 'releases',
'--org', sentryOrg, '--project', sentryProjectName,
'files', release, 'upload-sourcemaps', sourceMapsPath,
'--url-prefix', jsUrlPrefix, "--no-sourcemap-reference"
],
{stdio: "inherit"}
);
spawn(
'find',
[sourceMapsPath, '-type' ,'f', '-iname', '\*.js.map', '-delete'],
{stdio: "inherit"}
);
Sentry Project -> Settings -> Search (Auth Tokens) -> Create new token
COMMIT_HASH=${COMMIT_HASH} node ./upload-source-maps-to-sentry.js
Project -> Releases -> {Commit_Hash} -> Artifacts
To achieve that, send a
release
attribute along with the sentry init configuration, Here’s a sample config for @Sentry/browser 5.7.1
window.Sentry.init({
dsn: '<sentry_dsn>',
release: '<COMMIT_HASH>',
})