Spago不使用源映射来引用堆栈跟踪中错误的源代码位置。
这是我的Main.purs
f :: Unit -> Unit
f _ = unsafeCrashWith "error"
main :: Effect Unit
main = do
pure $ f unit我运行了以下命令来构建和运行程序:
spago build --purs-args "-g source maps"
spago run在输出中,我获得了对index.js文件中行的引用。
<my-project>/output/Partial/foreign.js:6
throw new Error(msg);
^
Error: error
at exports._crashWith (<my-project>/output/Partial/foreign.js:6:9)
at <my-project>/output/Partial.Unsafe/index.js:8:35
at exports._unsafePartial (<my-project>/output/Partial.Unsafe/foreign.js:6:10)
at Object.unsafeCrashWith (<my-project>/output/Partial.Unsafe/index.js:7:12)
at f (<my-project>/output/Main/index.js:14:27)
at Object.<anonymous> (<my-project>/output/Main/index.js:16:63)
at Module._compile (internal/modules/cjs/loader.js:1072:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)
at Module.load (internal/modules/cjs/loader.js:937:32)
at Function.Module._load (internal/modules/cjs/loader.js:778:12)我希望此堆栈跟踪使用源映射来引用实际的纯文本源代码位置。
发布于 2022-04-14 11:12:56
好的,这里有很多。有些是你的错误,有些是没有记录的问题。
因此,首先,如果您运行purs compile --help,您应该会看到下面的部分:
-g,--codegen ARG Specifies comma-separated codegen targets to include.
Accepted codegen targets are 'corefn', 'docs', 'js',
'sourcemaps'. The default target is 'js', but if this
option is used only the targets specified will be
used.这给了我们两条信息:
sourcemaps (没有空格),而不是source maps。所以你的参数应该是--purs-args "-g sourcemaps"sourcemaps,那么您将只获得源映射,而不是实际的JS输出。所以你的参数应该是--purs-args "-g sourcemaps,js"但是除了这两个之外,还有一个没有记录的问题:在-g之后不应该有任何空间(惊喜!)
好吧,公平地说,这不是那么狂野,这是一种有点被接受的模式。就像这样:
--purs-args "-gsourcemaps,js"--purs-args "--codegen=sourcemaps,js"好的,现在,如果您运行spago build --purs-args "-gsourcemaps,js",您应该会看到在index.js文件旁边生成的index.js.map文件。到目前一切尚好。
但是.哦不!当您使用spago run时,仍然只看到JS调用堆栈。到底怎么回事?
实际上,即使Node 是否支持从v12.12开始的源映射?,默认情况下它们也是禁用的。您必须通过将--enable-source-maps参数传递给Node本身来显式地启用它们。为了将额外的参数传递给Node,Spago提供了方便的-b|--node-args选项。
因此,将以上所有内容综合起来,下面是您的最后解决方案:
> spago build --purs-args "-gsourcemaps,js"
...
> spago run --node-args "--enable-source-maps"
Error: error
at exports._crashWith (C:\o\purs-pg\output\Partial\foreign.js:6:9)
at C:\o\purs-pg\output\Partial.Unsafe\index.js:8:35
-> C:\o\purs-pg\.spago\partial\v3.0.0\src\Partial\Unsafe.purs:24:23
at exports._unsafePartial (C:\o\purs-pg\output\Partial.Unsafe\foreign.js:6:10)
at Object.unsafeCrashWith (C:\o\purs-pg\output\Partial.Unsafe\index.js:7:12)
-> C:\o\purs-pg\.spago\partial\v3.0.0\src\Partial\Unsafe.purs:24:23
at f (C:\o\purs-pg\output\Main\index.js:39:27)
-> C:\o\purs-pg\src\Main.purs:79:1
at Object.<anonymous> (C:\o\purs-pg\output\Main\index.js:41:63)
-> C:\o\purs-pg\src\Main.purs:84:10
at Module._compile (internal/modules/cjs/loader.js:1158:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)
at Module.load (internal/modules/cjs/loader.js:1002:32)
at Function.Module._load (internal/modules/cjs/loader.js:895:16)最后,我想指出,Spago本身有一个参数-x|--source-maps,出于某种原因,它允许run和build命令,但实际上并不适用于它们:它只适用于bundle-app和bundle-module。
https://stackoverflow.com/questions/71832250
复制相似问题