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.

sourceRoot doesn't work for files in sub folders

See original GitHub issue

I have stored my source files in a number of sub folders.

It looks like the sourceRoot parameter doesn’t correctly handle those files. It doesn’t consider the relative part beginning at the sources’ root up to their actual location when creating the source map entry.

sourcemaps
Please refer to this issue for reference:

https://github.com/Microsoft/vscode/issues/4705

Issue Analytics

  • State:open
  • Created 7 years ago
  • Reactions:13
  • Comments:16

github_iconTop GitHub Comments

3reactions
jacameracommented, Oct 4, 2016

I agree that the sourceRoot option does not work as expected when assigning a string value and source files are located in sub directories.

Here’s a workaround using the path util:

const path = require('path');
// ...
sourceRoot: (file) => {
    return path.join(path.relative(path.join(outputDir, path.dirname(file.relative)), '.'), sourceDir);
}
3reactions
zhakhalovcommented, Jun 16, 2016

Hi I’ve got same issue Thanks @ckiely91. Your solution was very helpful. Here is my full task for “Node.js targeted” TS. Hope it would be useful…

gulp.task('build', () => {
  const project = ts.createProject('tsconfig.json');
  return gulp.src('./app/**/*.ts')
    .pipe(sourcemaps.init())
    .pipe(ts(project))
    .js
    .pipe(sourcemaps.write('./', {
      includeContent: false,
      sourceRoot: file => `${'../'.repeat(file.relative.split(/^win/.test(process.platform) ? '\\' : '/').length)}app`
    }))
    .pipe(gulp.dest('./dist'));
});

I found following code in sources of plugin

    if (typeof options.sourceRoot === 'function') {
      sourceMap.sourceRoot = options.sourceRoot(file);
    } else {
      sourceMap.sourceRoot = options.sourceRoot;
    }

Looks like sourceMap passed to output as is without, resolution of extra ../

Read more comments on GitHub >

github_iconTop Results From Across the Web

Pycharm: Marking a folder as 'sources root' is not recursive ...
py files needs to be explicitly added as 'sources root' in order for the IDE to resolve all references. Can this be done...
Read more >
Configuring Project Structure | PyCharm Documentation
In PyCharm, content is a collection of files with which you are currently working, possibly organized in a hierarchy of subfolders. The top-level...
Read more >
Robocopy does not copy the root folder and its time stamp
My test worked, I create a few folders and sub folders, c:\testing was root ... been to run the robocopy command to copy...
Read more >
Apply View Format to all Sub-folders
Windows File Explorer sets views by folder type (i.e contents). It does not have any option to set views on a folder tree...
Read more >
Specify source directories and files - Isilon Online Help
In the Source Cluster area, in the Source Root Directory field, type the full path of the source directory that you want to...
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