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

Sourcemap file is not working in the renderer using require() #13730

Closed
remss opened this issue Jul 19, 2018 · 10 comments
Closed

Sourcemap file is not working in the renderer using require() #13730

remss opened this issue Jul 19, 2018 · 10 comments
Labels
2-0-x 4-2-x 8-x-y bug 🪲 platform/windows status/confirmed A maintainer reproduced the bug or agreed with the feature

Comments

@remss
Copy link

remss commented Jul 19, 2018

  • Electron Version: 2.0.5
  • Operating System (Platform and Version): Win10 amd64
  • Last known working Electron version: None

With a project like this:

.
+-- dist
¦   +-- main.js
¦   +-- main.js.map
¦   +-- renderer.js
¦   +-- renderer.js.map
+-- index.html
+-- src
    +-- main.ts
    +-- renderer.ts

In index.html use require('dist/renderer.js') from the HTML page.

Expected Behavior
The console messages triggered by dist/renderer.js should have src/renderer.ts as origin in devtools because the sourcemap file renderer.js.map points to ../src/renderer.ts
The source file src/renderer.ts should be listed in the source panel

Actual behavior
The console messages have dist/renderer.js as origin in devtools
The source file src/renderer.ts does not appear in the source panel

To Reproduce

$ git clone https://github.com/remss/electron-typescript-sourcemap-issue.git
$ npm install
$ npm run build
$ npm start

Screenshots
image

@remss
Copy link
Author

remss commented Nov 19, 2018

This issue persists in Electron 3.0.9
@ckerr do you have any update on this please?

@remss
Copy link
Author

remss commented Nov 19, 2018

Until it is fixed I use vscode debugger. Here is my launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Electron: Main",
            "type": "node",
            "request": "launch",
            "program": "${workspaceRoot}\\dist\\main.js",
            "protocol": "inspector",
            "runtimeExecutable": "${workspaceRoot}\\node_modules\\.bin\\electron.cmd",
            "runtimeArgs": [
                "--remote-debugging-port=9223",
            ],
            "sourceMaps": true,
            "stopOnEntry": false, // if true it will break in a unknown file
            "outputCapture": "std" // for console.log to be displayed in debugger console
        },
        {
            "name": "Electron: Renderer",
            "type": "chrome",
            "request": "attach",
            "port": 9223,
            "webRoot": "${workspaceFolder}",
            "timeout": 10000,
            "sourceMaps": true,
            "url": "file:///C:/tmp/electron-typescript-sourcemap-issue-git/index.html"
        },
    ]
}

You must remplace the "url" value with the correct path (see https://github.com/Microsoft/vscode-chrome-debug/issues/438)

Both debug sessions main and renderer supports sourcemap correctly.

@remss
Copy link
Author

remss commented Jan 28, 2019

This issue persists in Electron 4.0.2 + TypeScript 3.2
Could you please tell me if electron team plan to fix it?

@c3er
Copy link

c3er commented Apr 18, 2019

@remss wrote

Until it is fixed I use vscode debugger. Here is my launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Electron: Main",
            "type": "node",
            "request": "launch",
            "program": "${workspaceRoot}\\dist\\main.js",
            "protocol": "inspector",
            "runtimeExecutable": "${workspaceRoot}\\node_modules\\.bin\\electron.cmd",
            "runtimeArgs": [
                "--remote-debugging-port=9223",
            ],
            "sourceMaps": true,
            "stopOnEntry": false, // if true it will break in a unknown file
            "outputCapture": "std" // for console.log to be displayed in debugger console
        },
        {
            "name": "Electron: Renderer",
            "type": "chrome",
            "request": "attach",
            "port": 9223,
            "webRoot": "${workspaceFolder}",
            "timeout": 10000,
            "sourceMaps": true,
            "url": "file:///C:/tmp/electron-typescript-sourcemap-issue-git/index.html"
        },
    ]
}

You must remplace the "url" value with the correct path (see Microsoft/vscode-chrome-debug#438)

Both debug sessions main and renderer supports sourcemap correctly.

Thanks! This works for me.

I changed the line (similar to)

"url": "file:///C:/tmp/electron-typescript-sourcemap-issue-git/index.html"

to

"url": "file:///${workspaceRoot}/index.html"

PS:

  • Electron 4.1.4
  • TypeScript 3.4.3

@sofianguy sofianguy added the 4-2-x label Aug 9, 2019
@emlai
Copy link

emlai commented Nov 17, 2019

I was able to get sourcemaps working by enabling both inlineSourceMap and inlineSources in tsconfig.json.

@sofianguy
Copy link
Contributor

@remss does @emlai's reported solution work for you?

We are no longer supporting Electron versions older than 6.x.y. Please let us know if the above solution does not work for you and if you are experiencing this on a later version of Electron.

@sofianguy sofianguy added the blocked/need-info ❌ Cannot proceed without more information label Feb 14, 2020
@remss
Copy link
Author

remss commented Feb 17, 2020

The workaround using "inlineSourceMap":true and "inlineSources":true in tsconfig.json is working.
And yes the issue with "sourceMap":true is still here with Electron 8.0.1

@remss remss changed the title Sourcemap is not working in the renderer using require() Sourcemap file is not working in the renderer using require() Feb 17, 2020
@electron-triage electron-triage added 8-x-y and removed blocked/need-info ❌ Cannot proceed without more information labels Feb 19, 2020
@hendimarcos
Copy link

@remss wrote

Until it is fixed I use vscode debugger. Here is my launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Electron: Main",
            "type": "node",
            "request": "launch",
            "program": "${workspaceRoot}\\dist\\main.js",
            "protocol": "inspector",
            "runtimeExecutable": "${workspaceRoot}\\node_modules\\.bin\\electron.cmd",
            "runtimeArgs": [
                "--remote-debugging-port=9223",
            ],
            "sourceMaps": true,
            "stopOnEntry": false, // if true it will break in a unknown file
            "outputCapture": "std" // for console.log to be displayed in debugger console
        },
        {
            "name": "Electron: Renderer",
            "type": "chrome",
            "request": "attach",
            "port": 9223,
            "webRoot": "${workspaceFolder}",
            "timeout": 10000,
            "sourceMaps": true,
            "url": "file:///C:/tmp/electron-typescript-sourcemap-issue-git/index.html"
        },
    ]
}

You must remplace the "url" value with the correct path (see Microsoft/vscode-chrome-debug#438)
Both debug sessions main and renderer supports sourcemap correctly.

Thanks! This works for me.

I changed the line (similar to)

"url": "file:///C:/tmp/electron-typescript-sourcemap-issue-git/index.html"

to

"url": "file:///${workspaceRoot}/index.html"

PS:

  • Electron 4.1.4
  • TypeScript 3.4.3

vscode also works with "url": "file: /// $ {workspaceRoot} /dist/**/*.html"

@shrinktofit
Copy link

Maybe related #22996 (comment)

@electron-triage
Copy link

The Electron version reported on this issue is no longer supported. See our supported versions documentation.

If this is still reproducible on a supported version, please open a new issue with any other new information that a maintainer should know.

Thank you for taking the time to report this issue and helping to make Electron better! Your help is appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2-0-x 4-2-x 8-x-y bug 🪲 platform/windows status/confirmed A maintainer reproduced the bug or agreed with the feature
Projects
None yet
Development

No branches or pull requests

8 participants