When debugging with vs-code im allways on line ahead in cjs-modules.
I think that is the culprit ;)
Using no newline at the end might fix the problem.
My Workaround:
original:
{
"mappings": "AAKkD;AAMqC;AAuBvF"
^ insert here
}
quick and dirty fix:
{
"mappings": ";AAKkD;AAMqC;AAuBvF"
^ inserted here
}
Thanks for reporting this, @juwens!
@juwens BTW, are you using V8 or JScript?
i'm using V8, specifically :
I guess that's not ideal, because i'm not using your pure package.
I can create a minimal exsample. But it might take a few days.
Hi @juwens,
I can create a minimal sample. But it might take a few days.
That shouldn't be necessary, especially since this is a debugging issue, but it would be great if you could provide a brief description of how to reproduce the issue. For example, what tools are you using to process your JavaScript code and create the sourcemap?
Thanks!
webpack5 + ts-loader:
Check source <-> output <-> map-file correctness with https://sokra.github.io/source-map-visualization/
use module with ClearScript
var engine = new V8ScriptEngine("", V8ScriptEngineFlags.EnableDebugging | V8ScriptEngineFlags.AwaitDebuggerAndPauseOnStart, 9222);
var javascriptStr = System.IO.File.ReadAllText("c:/dev/proj/dist/bundle.js");
var fileUri = new Uri("c:/dev/proj/dist/bundle.js");
var mapUri = new Uri(fileUri + ".map");
var documentInfo = new DocumentInfo(fileUri)
{
Category = ModuleCategory.Standard,
SourceMapUri = mapUri,
};
var doc = new StringDocument(documentInfo, javascriptStr);
engine.DocumentSettings.AddSystemDocument("foobar", doc);
var js = @"
const foobar = require('foobar');
let inst = new foobar.MyClass();
inst.DoSomething();
";
engine.Evaluate(new DocumentInfo
{
Category = ModuleCategory.CommonJS,
Flags = DocumentFlags.None,
}, js);
then attach with VS-Code with debugger 'node' or 'pwa-node':
"launch": {
"version": "0.2.0",
"configurations": [
{
"name": "Attach to ClearScript V8 on port 9222",
"type": "node",
"request": "attach",
"protocol": "inspector",
"address": "localhost",
"port": 9222
}
]
}
Hi @juwens,
Unfortunately we haven't found a way to fix this scenario in ClearScript.
Removing the CommonJS preamble newline doesn't work. It leaves the first-line source mappings broken, which is especially problematic in this case, as all the code is packed into that line.
We also tried to use a V8 feature whereby the host can specify where the code starts within a document, but that only served to confuse debuggers further.
On the other hand, adjusting the source map as you suggest works perfectly. It would be great if webpack had some way to specify an offset for the source map, but that doesn't seem to be the case. Luckily the source map is a JSON object that shouldn't be difficult to patch automatically during the build process.
Sorry!
@ClearScriptLib
Thanks for the effort.
i'm using V8, specifically :
- https://www.nuget.org/packages/JavaScriptEngineSwitcher.V8/3.5.5 (which containes a bundled ClearScript 6.0.2)
- https://www.nuget.org/packages/JavaScriptEngineSwitcher.V8.Native.win-x86/3.5.5
I guess that's not ideal, because i'm not using your pure package.
@juwens In the JavaScript Engine Switcher version 3.9.0 was solved this problem. Now the JavaScriptEngineSwitcher.V8 package depends on the official package (Microsoft.ClearScript.V8). After upgrading to version 3.9.0, you should also replace the JavaScriptEngineSwitcher.V8.Native.win-x86 package by the Microsoft.ClearScript.V8.Native.win-x86 package.