question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Uploading source maps for Typescript files

See original GitHub issue

Hi.

I’m trying to upload the source maps of a NodeJS project written in Typescript to Bugsnag. The code doesn’t get minified, uglyfied or concatenated. Just compiled from Typescript to Javascript. The project is running on Firebase Functions.

First of all is this even possible to upload the source maps for Typescript to be shown on the dashboard?

Steps to reproduce

What I tried is using the bugsnag-sourcemaps package to upload the source maps manually. I also triggered the following error: Preview

Currently I’m just trying to upload the single source map file in which the error is thrown

const upload = require('bugsnag-sourcemaps').upload;
const glob = require('glob');
const bugsnagKey = '...';
const path = require('path');

const projectRoot = path.resolve(__dirname, '..');
const dist = path.resolve(projectRoot, 'dist');

glob(`${dist}/app/controllers/internal_controller.js.map`, (err, files) => {
	if (err) throw err;

	Promise.all(files.map(processMap))
		.then((result) => {
			console.log(result);
		})
		.catch((err) => {
			console.error(err);
			process.exit(1);
		});
});

function processMap(sourceMapFile) {
	const localFile = sourceMapFile.split('.map')[0];
	console.log('Local file:', localFile);
	const relativeFile = localFile.split(dist)[1];
	const remoteFileUrl = `/user_code/dist${relativeFile}`;
	console.log('URL:', remoteFileUrl);
	const tsFile = path.join(projectRoot, 'src', relativeFile.replace('.js', '.ts'));
	console.log('TS file:', tsFile);
	return upload({
		apiKey: bugsnagKey,
		// appVersion: appVersion,
		minifiedUrl: remoteFileUrl,
		sourceMap: sourceMapFile,
		minifiedFile: localFile,
		projectRoot: projectRoot,
		sources: {
			[remoteFileUrl]: tsFile
		},
		uploadSources: true,
		overwrite: true,
	});
};

Upload is a success and those lines get printed:

Local file: /home/dominic/workspace/tablechamp-api/dist/app/controllers/internal_controller.js
URL: /user_code/dist/app/controllers/internal_controller.js
TS file: /home/dominic/workspace/tablechamp-api/src/app/controllers/internal_controller.ts

Version

Using "bugsnag-sourcemaps": "^1.0.3",

Additional information

I’m not setting any project version while uploading. The error in the dashboard doesn’t show a version as well.

Project: freshfox/tablechamp-api

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
bengourleycommented, Feb 7, 2019

It shouldn’t be too hard, you’ll just want to glob over all .map files in your directory and call upload() on them, along with the appopriate parameters for bugsnag-sourcemaps.

const glob = require('glob')
const fs = require('fs')
const parallel = require('run-parallel-limit')
const { upload } = require('bugsnag-sourcemaps')

// find every .map file in your dist directory
glob('path/to/dist/**/*.map', (err, files) => {
  if (err) throw err

  // for each source map, get an upload function and
  // pass it to the parallel runner utility – this limits the
  // upload concurrency to 5 at once
  parallel(files.map(f => getUploadFn(f), 5, (err) => {
    if (err) throw err
    console.log('done')
  })
})

function getUploadFn (f) {
  return () => {
    console.log(`Uploading source map ${f}`)
    upload({
      apiKey: 'YOUR_API_KEY_HERE',
      appVersion: '1.2.3',
      // this must match the path that will appear in your error reports
      minifiedUrl: path.relative(projectRoot, f.replace(/\.map$/, '')),
      // this is the path to the source map
      sourceMap: f,
      // this is the path to the js file that the source map is for
      minifiedFile: f.replace(/\.map$/, '')
    })
  }
}

Note that this is just a sketch – I just wrote it directly here on GitHub and didn’t run it!

1reaction
bmakuhcommented, Feb 7, 2019

Thanks for the great explanation!

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeScript (tsc) for Connect - Sentry Documentation
Upload your source maps using tsc and Sentry CLI.
Read more >
Upload Source Maps - OpenReplay docs
OpenReplay supports un-minifying JavaScript via source maps. By uploading them to OpenReplay, you will be able to see the source code context obtained...
Read more >
Uploading Source Maps for JavaScript - Sentry Documentation
The recommended way to upload source maps is using sentry-cli. If you have used Sentry Wizard to set up your project, it has...
Read more >
Upload JavaScript Source Maps - Datadog Docs
Note: If you are using TypeScript, set compilerOptions.sourceMap to true in your tsconfig.json file.
Read more >
What is TypeScript Map file ? - GeeksforGeeks
All you have to do is Upload Source Map to Dev tools and Internally all browsers support Source Map and the Emitted JavaScript...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found