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.

Chrome: SourceMap links not working

See original GitHub issue

Hi there,

loving this library, using it every day with pure joy! 😃

One of the coolest features might be the generated links to jump directly to the source. For some reason, that doesn’t work for me. Clicking on one of the links just opens a new tab to about:blank instead:

image

(after clicking on the link)

image

Manually, I can open the file in the DevTools just fine:

image

Angular version 13.0.2: ngx-logger version: 5.0.7 Chrome version: 97.0.4692.99 (running in debug mode without any plugins enabled)

Configuration (in app.module.ts):

imports: [
...
HttpClientModule,
LoggerModule.forRoot({
  level: environment.production ? NgxLoggerLevel.INFO : NgxLoggerLevel.DEBUG,
  serverLogLevel: NgxLoggerLevel.OFF,
  timestampFormat: 'HH:mm:ss.SSS',
  enableSourceMaps:true
})
]
  • I started angular dev environment with ng serve

Build config from angular.json:

    {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "outputPath": "dist",
            "index": "src/index.html",
            "main": "src/main.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "tsconfig.app.json",
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ],
            "stylePreprocessorOptions": {
              "includePaths": [
                "src/styles"
              ]
            },
            "styles": [
              "./node_modules/@angular/material/prebuilt-themes/indigo-pink.css",
              "src/styles.scss"
            ],
            "scripts": [],
            "vendorChunk": true,
            "extractLicenses": false,
            "buildOptimizer": false,
            "sourceMap": true,
            "optimization": false,
            "namedChunks": true
          }

Did I miss something?

Thank you!

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:6

github_iconTop GitHub Comments

2reactions
BenniG82commented, Mar 26, 2022

This works for me:

Extend the NGXLoggerWriterService and replace prepareMetaString with your own implementation that removes the leading “.” and adds ‘webpack://’.

import { Injectable } from '@angular/core';
import { INGXLoggerConfig, INGXLoggerMetadata, NgxLoggerLevel, NGXLoggerWriterService } from 'ngx-logger';

@Injectable({
  providedIn: 'root'
})
export class MyLoggerWriterService extends NGXLoggerWriterService {
 protected prepareMetaString(metadata: INGXLoggerMetadata, config: INGXLoggerConfig): string {
    const fileName = metadata.fileName?.charAt(0) === '.' ? 'webpack://' + metadata.fileName?.substring(1) : metadata.fileName;
    return super.prepareMetaString({ ...metadata, fileName }, config);
  }
}

Configure ngx-logger to use it:

LoggerModule.forRoot({/* your log-config here */}, {
      writerProvider: { provide: TOKEN_LOGGER_WRITER_SERVICE, useClass: MyLoggerWriterService }
    }),

Maybe there is a better way, but this works (at least on my machine 😄 ) How I came up with webpack://? Thats what I saw, when hovering over the source of console.log statements: image

Sample output:

2022-03-26T13:22:56.331Z TRACE [webpack:///src/app/core/services/auth/authentication.service.ts:77:0] Token is still valid
0reactions
spyro2000commented, Apr 1, 2022

This works!! So many thanks!

So together with the fix for the missing linebreak before the actual message the writer should look like this:

protected override prepareMetaString(metadata: INGXLoggerMetadata, config: INGXLoggerConfig): string {
    // Fix link to the source file in the console
    const fileName = metadata.fileName?.charAt(0) === '.'
      ? 'webpack://' + metadata.fileName?.substring(1)
      : metadata.fileName

    // We want to start the actual log message on a new line (after level + source link)
    return super.prepareMetaString({ ...metadata, fileName }, config) + '\n'
  }

(For some reason there is still an additional space added before the start of the actual message but it’s already way more readable).

Read more comments on GitHub >

github_iconTop Results From Across the Web

chrome, source map not loading - Stack Overflow
For chrome, source-map was not loading/working for me too. I kept on seeing the bundle.js files. However, in other browsers it worked, ...
Read more >
source maps are not working when debugging with chrome
Version: 6.3.1 + Platform: OSX I am debugging my mocha tests using native node debugger, using the following command: /usr/local/bin/node ...
Read more >
The source maps don't work in Developer Tools when ...
When I run on the iOS device Safari has no problem extracting the source map and I can debug correctly. Here's the screen...
Read more >
4 Reasons Why Your Source Maps are Broken - Sentry Blog
Missing original source files​​ This likely means that your source map doesn't contain or link to your original source files. Without your ...
Read more >
Sourcemap not working - Help - OpenFL Community
I've checked the .map file and I can see "sourceRoot":"file:///", so the URL of the files should be file ...
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