1

I have a project using Angular 13 on electron 18 where the source maps seem to link to the wrong source lines when I set the target in tsconfig.json to anything higher than es5. If I place breakpoints, they're not hit, or if they're hit and I go up the call stack, it points to a part of code I can't be in at that point. Some files are just 1 line off, others are 5 or even 10 lines off. What could cause this?

However, if I don't set it to es2020, I get compilation errors with esbuild trying to build a production version: with es5, it complains about

"ERROR: Transforming const to the configured target environment ("es5") is not supported yet",

while with es2015 up to es2017, the error is

"ERROR: Big integer literals are not available in the configured target environment".

Since transpilation is done in memory I have no idea where these consts and BigInts are coming from (my own code is full of const, but I never used BigInt anywhere).

I already tried previous versions of electron (14, 16) and downgrading Angular to 12, but it doesn't seem to make a difference. node is at v16.13.2 (using nvm).

This project is already 5 years old and I tried to keep it up to date (originally used Angular 1) and I haven't had this before, but it seems to have gotten introduced with a recent update.

I have no idea where to start looking, really...

The webpack target is set to electron-renderer

This is my tsconfig.json:

{
  "compileOnSave": false,
  "compilerOptions": {
    "outDir": "./dist/out-tsc",
    "module": "es2020",
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "allowSyntheticDefaultImports": true,
    "downlevelIteration": true,
    "allowJs": true,
    "target": "es2017",
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
        "es2020",
        "es2017",
        "es2016",
        "es2015",
        "dom"
    ]
  },
  "exclude": [
    "node_modules"
  ],
  "angularCompilerOptions": {
    "strictTemplates": true,
    "fullTemplateTypeCheck": true,
    "annotateForClosureCompiler": true,
    "strictInjectionParameters": true,
    "skipTemplateCodegen": false,
    "preserveWhitespaces": true,
    "skipMetadataEmit": false,
    "disableTypeScriptVersionCheck": true
  }
}

These are my build scripts:

    "postinstall": "electron-builder install-app-deps",
    "ng": "ng",
    "start": "npm-run-all -p electron:serve ng:serve",
    "build": "ng build --base-href ./ ",
    "build:dev": "npm run build -- -c dev && npm run electron:serve-tsc",
    "build:prod": "npm run build -- -c production && npm run electron:serve-tsc",
    "ng:serve": "ng serve -c dev",
    "electron:serve-tsc": "tsc -p tsconfig.serve.json",
    "electron:serve": "wait-on tcp:4200 && npm run electron:serve-tsc && npx electron . --serve --devtools --trace-warnings",
    "electron:local": "npm run build:prod && npx electron .  --devtools",
    "electron:linux": "npm run build:prod && rm -rf ./release/*.rpm ./release/*.deb ./release/*.AppImage ./release/linux-unpacked && electron-builder build --linux",
    "electron:windows": "npm run build:prod && rm -rf ./release/*.exe ./release/win-unpacked && electron-builder build --windows",
    "electron:mac": "npm run build:prod && rm -rf ./release/*-mac.zip ./release/mac && electron-builder build --mac",
    "electron:all": "npm run build:prod && rm -rf ./release && electron-builder build -lmw",
unlord
  • 11
  • 5
  • I managed to work around it by specifying a second tsconfig.app.dev.json in the configurations part of angular.json that overrides the target to es5, but I would still very much like to understand why it was needed in the first place... Why are the source maps incorrect and why do I get those errors on es5 in production only? – unlord Apr 21 '22 at 15:30
  • [This answer](https://stackoverflow.com/a/67371788/4929911) on another stackoverflow post may help. – Pascal R. Jun 15 '22 at 11:15

0 Answers0