electron / electron/forge

exception stack locations are incorrect when using typescript/webpack and asar

Open
#2,600 2 comments 3 reactions 0 assignees View on GitHub
plugin/webpack
Dominant language
TypeScript
Stars
7.1k
Forks
641
Avg merge
3d 17m
Merged PRs (30d)
32

Description

### Pre-flight checklist

- [X] I have read the [contribution documentation](https://github.com/electron-userland/electron-forge/blob/master/CONTRIBUTING.md) for this project.
- [X] I agree to follow the [code of conduct](https://github.com/electron/electron/blob/main/CODE_OF_CONDUCT.md) that this project uses.
- [X] I have searched the issue tracker for a bug that matches the one I want to file, without success.

### Electron Forge version

6.0.0-beta.61

### Electron version

v15.1.2

### Operating system

Windows 10 (19042.1320)

### Last known working Electron Forge version

_No response_

### Expected behavior

We have been troubleshooting some problems with our app, but the error stack traces are not accurately reflecting where in the code the errors occurred, which makes troubleshooting difficult.

When an error is thrown in our electron app, we would expect the `stack` attribute of that error to correctly point to the place in the webpack-generated index.js file, be it for main or renderer.

And when `packagerConfig.asar: false`, that `stack` attribute **does** point to the spot in the code where an error is created.

### Actual behavior

If `packagerConfig.asar: true`, the location given in the error's `stack` do **not** line up in the generated index.js with where the error was created.

### Steps to reproduce

We are setting `webpack.devtool: "source-map"`

I include a line during app initialization to print out a stack trace, just to see what is going on, just to show that this is not an issue with our error reporting module:
```
logger.warn(new Error("test error"));
```

running the make process and comparing the logged error's stack locations with the generated webpack artifacts, it does not point at the correct place when `packagerConfig.asar: true`

### Additional information

forge.config.js
```javascript
const fs = require("fs");
const path = require("path");
const packageJson = require("./package.json");

const { desktopProductName, version } = packageJson;
const ignore = (file) => {
if (!file) return false;
// Adding .map files to what's in @electron-forge/webpack-plugin
return !/^[/\\]\.webpack($|[/\\]).*$/.test(file) || /\.js\.map$/.test(file);
};

const config = {
packagerConfig: {
name: desktopProductName,
appBundleId: "com.electron.my-ap",
appCategoryType: "public.app-category.business",
asar: true,
darwinDarkModeSupport: true,
extraResource: ["resources", "static/images/tray", "static/app-update.yml"],
icon: path.resolve(__dirname, "static", "images", "icon", "standard-color"),
ignore: ignore,
protocols: [
{
name: "com.electron.my-app",
schemes: ["myapp"],
},
],
},
makers: [
{
name: "@electron-forge/maker-squirrel",
platforms: ["win32"],
config: {
iconUrl: "https://XXX.cloudfront.net/MyApp/icons/standard-color.ico",
loadingGif: "./static/images/installer/install_splash.gif",
name: "my_app",
noMsi: true,
setupExe: `${desktopProductName}-${version} Setup.exe`,
setupIcon: "./static/images/icon/standard-color.ico",
},
},
{
name: "@electron-forge/maker-dmg",
config: {
background: "static/images/installer/background.png",
contents: [
{ x: 422, y: 256, type: "link", path: "/Applications" },
{
x: 237,
y: 256,
type: "file",
path: path.join(__dirname, "out", `${desktopProductName}-darwin-x64`, `${desktopProductName}.app`),
},
],
icon: "./static/images/icon/standard-color.icns",
},
},
{
name: "@electron-forge/maker-zip",
platforms: ["darwin"],
},
],
plugins: [
[
"@electron-forge/plugin-webpack",
{
devContentSecurityPolicy:
"default-src 'self' 'unsafe-inline' data:; script-src 'self' 'unsafe-eval' 'unsafe-inline' data:",
mainConfig: "./webpack.main.config.js",
renderer: {
config: "./webpack.renderer.config.js",
entryPoints: [
{
html: "./src/renderer/index.html",
js: "./src/renderer/index.tsx",
name: "main_window",
},
],
nodeIntegration: true,
},
port: 3005,
},
],
],
};

module.exports = config;
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.