Page 1 of 1

Debugging Strangeness

Posted: Thu Feb 05, 2026 5:27 pm
by DtM
Hello everyone,

I've been running into some strangeness when trying to debug a new script.

I am on Switch 25.11, running Visual Studio Code Version: 1.108.1.

When I attach the debugger to my script, I get taken to the NodeScriptExecutor.js script as you would expect.

Upon pressing the Continue button expecting to be taken to my actual main.js file, I instead see another file called outMain.js, which has the following contents:

Code: Select all

Could not load source 'd:\Automation Resources\Scripts\Switch Scripts\ProductionTrackerImporter\outMain.js': Error processing source: RangeError: Invalid count value: -2
	at String.repeat (<anonymous>)
	at Ua.content (c:\Users\workflow\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\ms-vscode.js-debug\src\extension.js:67:3)
	at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
	at async r._onSource (c:\Users\workflow\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\ms-vscode.js-debug\src\extension.js:131:3006)
	at async pu._onMessage (c:\Users\workflow\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\ms-vscode.js-debug\src\extension.js:48:5028).
Any attempt to find out what is causing this using the debug tools takes me into the obfuscated Enfocus scripts, which I am obviously unable to decipher.

If I press continue again, my script does run, but none of my breakpoints are honored, meaning I am unable to debug what is actually failing in my script.

Has anyone come across a problem like this before?

Any help is greatly appreciated!

Many thanks,

Dan

Re: Debugging Strangeness

Posted: Fri Feb 06, 2026 11:39 am
by DtM
Just wanted to give an update that I've tried setting up a brand new Script with the SwitchScriptTool.

I tried it with both a simple jobArrived and timerFired function, both suffer from the same issue.

I'm completely stumped as to what is causing this!

Re: Debugging Strangeness

Posted: Fri Feb 06, 2026 3:46 pm
by freddyp
The fact that there is an outMain.js means that Switch has had to do some processing on the file to make it work in a CommonJS environment. Does your script use ES Modules? Are you debugging a script folder or a packed script? Adding breakpoints to the outMain.js should work, or doesn't it? It is not ideal to debug like this because you will have to set the breakpoints every time, but it is better than nothing.

I have never seen this before, but then again I always work with TypeScript.

Re: Debugging Strangeness

Posted: Fri Feb 06, 2026 4:15 pm
by DtM
freddyp wrote: Fri Feb 06, 2026 3:46 pm The fact that there is an outMain.js means that Switch has had to do some processing on the file to make it work in a CommonJS environment. Does your script use ES Modules? Are you debugging a script folder or a packed script? Adding breakpoints to the outMain.js should work, or doesn't it? It is not ideal to debug like this because you will have to set the breakpoints every time, but it is better than nothing.

I have never seen this before, but then again I always work with TypeScript.
Hi Freddy,

In my latest test I didn't include any 3rd party modules, this is the whole script:

Code: Select all

async function jobArrived(s, flowElement, job) {
    await flowElement.log(LogLevel.Info, 'First log!')
    await flowElement.log(LogLevel.Warning, 'Second log!')
    await flowElement.log(LogLevel.Error, 'Third log!')
    await job.sendToSingle()
}
And that is still leading to the same error:

Code: Select all

Could not load source 'd:\Automation Resources\Scripts\Switch Scripts\Test\outMain.js': Error processing source: RangeError: Invalid count value: -2
	at String.repeat (<anonymous>)
	at Ua.content (c:\Users\workflow\AppData\Local\Programs\Microsoft VS Code\bdd88df003\resources\app\extensions\ms-vscode.js-debug\src\extension.js:67:3)
	at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
	at async r._onSource (c:\Users\workflow\AppData\Local\Programs\Microsoft VS Code\bdd88df003\resources\app\extensions\ms-vscode.js-debug\src\extension.js:131:3006)
	at async pu._onMessage (c:\Users\workflow\AppData\Local\Programs\Microsoft VS Code\bdd88df003\resources\app\extensions\ms-vscode.js-debug\src\extension.js:48:5028).
I am using script folders, created in the following manner:

Code: Select all

SwitchScriptTool --create Test  . --JavaScript
I don't actually have a file called outMain.js in my script folder, even though the error is suggesting that there is one, so I am unable to add breakpoints to it.

I'll try making a TypeScript version instead to see if the issue persists, I wonder if there is some kind of bug with standard JS in 25.11?

Re: Debugging Strangeness

Posted: Fri Feb 06, 2026 4:30 pm
by DtM
Now that I've made a TypeScript version of my test file, I get different behavior, but it is still not as you would expect.

When I attach this version, I get the SwitchScriptExecutor.js as normal, upon clicking continue, the script displays line 611 of the NodeScriptExecutor.js file.

Again, this is obfuscated so I am unable to tell what exactly is happening. I also do not know why/how it has stopped here as there are no breakpoints on this file and I have caught and uncaught exceptions unticked also. Clicking continue again leads to my script being run, but ignoring the breakpoints.

I have included the call stack in the hope that it helps:

Code: Select all

Object._lookForNodeModuleVM (c:\Program Files\Enfocus\Enfocus Switch\ScriptExecutor\NodeScriptExecutor.js:611)
<anonymous> (outMain.js:14)
_0x369802.run (c:\Program Files\Enfocus\Enfocus Switch\ScriptExecutor\NodeScriptExecutor.js:608)
await (Unknown Source:0)
<anonymous> (c:\Program Files\Enfocus\Enfocus Switch\ScriptExecutor\NodeScriptExecutor.js:403)
await (Unknown Source:0)
emit (<node_internals>/events:518)
emit (<node_internals>/internal/child_process:951)
processTicksAndRejections (<node_internals>/internal/process/task_queues:83)
TickObject (Unknown Source:0)
init (<node_internals>/internal/inspector_async_hook:25)
emitInitNative (<node_internals>/internal/async_hooks:202)
emitInitScript (<node_internals>/internal/async_hooks:505)
nextTick (<node_internals>/internal/process/task_queues:132)
handleMessage (<node_internals>/internal/child_process:967)
<anonymous> (<node_internals>/internal/child_process:636)
callbackTrampoline (<node_internals>/internal/async_hooks:130)
PIPEWRAP (Unknown Source:0)
init (<node_internals>/internal/inspector_async_hook:25)
emitInitNative (<node_internals>/internal/async_hooks:202)
_forkChild (<node_internals>/child_process:177)
setupChildProcessIpcChannel (<node_internals>/internal/process/pre_execution:547)
prepareExecution (<node_internals>/internal/process/pre_execution:144)
prepareMainThreadExecution (<node_internals>/internal/process/pre_execution:54)
<anonymous> (<node_internals>/internal/main/run_main_module:11)

Re: Debugging Strangeness

Posted: Fri Feb 06, 2026 4:42 pm
by freddyp
I can reproduce the problem and apparently this has been logged before.

Re: Debugging Strangeness

Posted: Fri Feb 06, 2026 5:04 pm
by DtM
freddyp wrote: Fri Feb 06, 2026 4:42 pm I can reproduce the problem and apparently this has been logged before.
Hi Freddy,

At least that is reassuring that it isn't an issue with our environment.

Is there a knowledge base article or something similar that explains how I can work around the issue in the meantime?

Re: Debugging Strangeness

Posted: Fri Feb 06, 2026 5:40 pm
by samw
Hi Dan,

As Freddy mentioned, we are aware of this issue. It's already logged as a bug (internal ref ENFS-37977) and we will investigate and fix as soon as possible.

My initial finding is that this is related to the bundling enhancement in 25.11 where we skip the unnecessary ESBuild process when no ES modules are present. This process is only required to allow running of scripts with ES modules so is otherwise not required. However the problem is that it is the bundling which provides 'outMain.js' which is currently always expected for debugging.

Could you try installing the 'axios' package and adding an import at the top of your script (please note the 'import' syntax instead of 'require'):
import axios from 'axios';
Please could you let us know what happens when you attach to a debug session with this change? Does it work correctly now?

Re: Debugging Strangeness

Posted: Fri Feb 06, 2026 6:01 pm
by DtM
samw wrote: Fri Feb 06, 2026 5:40 pm Hi Dan,

As Freddy mentioned, we are aware of this issue. It's already logged as a bug (internal ref ENFS-37977) and we will investigate and fix as soon as possible.

My initial finding is that this is related to the bundling enhancement in 25.11 where we skip the unnecessary ESBuild process when no ES modules are present. This process is only required to allow running of scripts with ES modules so is otherwise not required. However the problem is that it is the bundling which provides 'outMain.js' which is currently always expected for debugging.

Could you try installing the 'axios' package and adding an import at the top of your script (please note the 'import' syntax instead of 'require'):
import axios from 'axios';
Please could you let us know what happens when you attach to a debug session with this change? Does it work correctly now?
Hi Sam,

Thanks for the information.

I've added axios into my script and can confirm I am now able to debug it correctly.

Am I right in saying that I only need to do this whilst debugging, and can remove the import (and uninstall axios from my script) once it's ready to push into production?

Thanks again,

Dan

Re: Debugging Strangeness

Posted: Fri Feb 06, 2026 6:29 pm
by samw
Hi Dan,

I'm glad to hear that it's working for you – thanks for the confirmation. It's not the nicest of workarounds but I hope it helps for now.

That is correct, you can remove the import and uninstall the module from your project once you are done debugging. You could even create a 'dummy' ES module for this purpose, but in that case your script may see a slight performance drop at runtime due to the bundling.

Something which might be of interest – if you do not want to see the obfuscated code of our internal files such as NodeScriptExecutor.js while debugging, you can exclude them in the .vscode/lanch.json file in your script folder. Just add them to the property "skipFiles", like this:

Code: Select all

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Attach",
      "port": 9229,
      "request": "attach",
      "skipFiles": [
        "<node_internals>/**",
        // Added these...
        "**/NodeScriptExecutor.js",
        "**/bind.js",
        "**/SwitchNodeScriptRunner.js",
        "**/nodemodules/**"
      ],
      "type": "node",
    }
  ]
}

Re: Debugging Strangeness

Posted: Mon Feb 09, 2026 4:03 pm
by DtM
samw wrote: Fri Feb 06, 2026 6:29 pm Hi Dan,

I'm glad to hear that it's working for you – thanks for the confirmation. It's not the nicest of workarounds but I hope it helps for now.

That is correct, you can remove the import and uninstall the module from your project once you are done debugging. You could even create a 'dummy' ES module for this purpose, but in that case your script may see a slight performance drop at runtime due to the bundling.

Something which might be of interest – if you do not want to see the obfuscated code of our internal files such as NodeScriptExecutor.js while debugging, you can exclude them in the .vscode/lanch.json file in your script folder. Just add them to the property "skipFiles", like this:

Code: Select all

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Attach",
      "port": 9229,
      "request": "attach",
      "skipFiles": [
        "<node_internals>/**",
        // Added these...
        "**/NodeScriptExecutor.js",
        "**/bind.js",
        "**/SwitchNodeScriptRunner.js",
        "**/nodemodules/**"
      ],
      "type": "node",
    }
  ]
}
Hi Sam,

Thanks for the advice, I'll try this next time I'm debugging my code!