Ok, there's quite a lot here. Some are your mistakes, some are undocumented gotchas.
So first of all, if you run purs compile --help
, you should see the following section in there:
-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.
This gives us two pieces of information:
- It should be
sourcemaps
(no spaces), not source maps
. So your parameter should be --purs-args "-g sourcemaps"
- If you only specify
sourcemaps
, you will get only source maps, no actual JS output. So your parameter should be --purs-args "-g sourcemaps,js"
But besides these two, there is an undocumented gotcha: there should be no space after -g
(surprise!)
Well, to be fair, it's not that wild, it's a somewhat accepted pattern. And it goes like this:
- For the short version of the parameter, the value should come right after the letter, no space. So
--purs-args "-gsourcemaps,js"
- For the long version, the value should come after an equals sign. So
--purs-args "--codegen=sourcemaps,js"
Ok, so now, if you run spago build --purs-args "-gsourcemaps,js"
, you should see index.js.map
files generated next to the index.js
files. So far so good.
But - oh no! When you spago run
, you still see JS callstack only. What's going on?
Well, turns out, even though Node does support source maps starting with v12.12, they are disabled by default. You have to enable them explicitly by passing the --enable-source-maps
parameter to Node itself. And in order to pass extra parameters to Node, Spago offers the handy -b|--node-args
option.
So, putting together all of the above, here's your final solution:
> 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)
In conclusion, I'd like to note that Spago itself has a parameter -x|--source-maps
, which is for some reason allowed for both run
and build
commands but in reality doesn't actually apply to them: it only works for bundle-app
and bundle-module
.