Skip to content
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

Generated Source Maps using absolute paths #17046

Closed
1 of 15 tasks
FERNman opened this issue Feb 21, 2020 · 6 comments · Fixed by #18377
Closed
1 of 15 tasks

Generated Source Maps using absolute paths #17046

FERNman opened this issue Feb 21, 2020 · 6 comments · Fixed by #18377

Comments

@FERNman
Copy link

FERNman commented Feb 21, 2020

🐞 Bug report

Command (mark with an x)

  • serve
  • build
  • e2e
  • generate
  • add
  • update
  • test
  • lint
  • xi18n
  • new
  • run
  • config
  • help
  • version
  • doc

Is this a regression?

I don't think so.

Description

When building an Angular application that imports a local library, the source maps for files outside of the apps' folder contain absolute paths instead of relative ones.

This happens because the context for the default Webpack config generated by the CLI internally is set to projectRoot. Webpack shortens the paths by looking into the current and the parent directory, which is not enough for the provided setup.

I propose to use either the TSConfig baseUrl as the context for the Webpack config (would make the most sense in my opinion because the paths aliases are relative to this path), or the workspaces root property.

🔬 Minimal Reproduction

Create a new project containing an application and a library. Import the library in the application through TS path aliases and build it with source maps enabled. The source maps will be using absolute paths.

A simple repo can be found here: https://github.com/FERNman/angular-source-maps
Just run ng build playground and go to any of the generated source maps in the dist folder. The path should be an absolute path.

Workaround

For anybody else stumbling across this issue, an easy workaround until this gets fixed is to change the root property of the app in question in the angular.json to the repositories' root.

🌍 Your Environment


Angular CLI: 9.0.1
Node: 12.10.0
OS: win32 x64

Angular: 9.0.0
... animations, cdk, common, compiler, compiler-cli, core, forms
... language-service, material, material-moment-adapter
... platform-browser, platform-browser-dynamic, router
... service-worker
Ivy Workspace: Yes

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.900.1
@angular-devkit/build-angular     0.900.1
@angular-devkit/build-optimizer   0.900.1
@angular-devkit/build-webpack     0.900.1
@angular-devkit/core              7.3.9
@angular-devkit/schematics        9.0.1
@angular/cli                      9.0.1
@ngtools/webpack                  9.0.1
@schematics/angular               9.0.1
@schematics/update                0.900.1
rxjs                              6.5.4
typescript                        3.7.5
webpack                           4.41.2
@xiaoxiangmoe
Copy link

@alan-agius4 How should this error be fixed? Should we set all projectRoot to "root": ""?

@alan-agius4
Copy link
Collaborator

alan-agius4 commented Jun 15, 2020

@xiaoxiangmoe, no you shouldn't amend the root to "", as this might cause issues when using ng update or other schematics.

There needs to be a fix for this in build-angular.

@xiaoxiangmoe
Copy link

Will this fix be brought in next month's Angular 10 release?

@FERNman
Copy link
Author

FERNman commented Jun 15, 2020

@xiaoxiangmoe I agree with @alan-agius4 , changing the root to the workspace dir breaks many scripts, including for example many of the schematics included in @nrwl/nx.

We're currently using a simple custom Webpack config and didn't experience any problems yet.

const path = require('path');

module.exports = {
  context: path.resolve(__dirname, '..')
};

The config lies in a folder called webpack in our workspaces' root directory. That's why we're setting the context to the parent folder.

The builder we're using is @angular-builders/custom-webpack.

@ghostlytalamaur
Copy link

This issue causes debugging problem using VSCode Remote Extensions. Breakpoints will not work until custom sourceMapPathOverrides in launch.json is specified.

@alan-agius4 alan-agius4 self-assigned this Jul 3, 2020
alan-agius4 added a commit that referenced this issue Sep 3, 2020
… paths in monorepo

With this change we fix the issue that when having a monorepo style workspace, sourcemaps sources references absolute paths.

Closes #17046
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Oct 4, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants