Failed to run a JS file when spago bundle-app with purescript-unordered-collections
I running this code on purs 0.14.5 and spago 0.20.3:
module Main where
import Prelude
import Data.HashMap (HashMap, empty, insert)
import Effect (Effect)
import Effect.Console (logShow)
type MyHash = HashMap String String
main :: Effect Unit
main = do
let o = empty
logShow $ insert "key" "value" o
it runs very well with command spago run.
when I bundle them with spago bundle-app and run it:
➜ Sample node index.js
D:\msys64\home\XGLey\Code\Purescript\Sample\index.js:474
Collision.prototype.lookup = function collisionLookup(Nothing, Just, keyEquals, key, keyHash, shift) {
^
ReferenceError: Collision is not defined
at D:\msys64\home\XGLey\Code\Purescript\Sample\index.js:474:3
at Object.<anonymous> (D:\msys64\home\XGLey\Code\Purescript\Sample\index.js:691:3)
at Module._compile (internal/modules/cjs/loader.js:1063:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
at internal/main/run_main_module.js:17:47
It seems Collision constructor is not in the bundled sources.
It looks like spago calls purs with -m argument instead of --main here.
Using direct call to purs works for me.
Reproduce:
➜ purs bundle 'output/*/*.js' -m Main -o target.js && node target.js
/home/me/c/repor-1/target.js:474
Collision.prototype.lookup = function collisionLookup(Nothing, Just, keyEquals, key, keyHash, shift) {
^
ReferenceError: Collision is not defined
at PS.Data.HashMap (/home/me/c/repor-1/target.js:474:3)
at Object.<anonymous> (/home/me/c/repor-1/target.js:691:3)
at Module._compile (internal/modules/cjs/loader.js:778:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3)
And with correct argument:
➜ purs bundle 'output/*/*.js' --main Main -o target.js && node target.js
(fromArray [(Tuple "key" "value")])
great, purs bunlde works.
thanks a lot.
I think we should not close this yet.
Yeah, I think this is some sort of bug? The result is indeed really puzzling:
-
spago bundle-appis a thin layer overpurs bundle "output/*/*.js" -m Main --main Main -o index.js - running that command still results in the failure, but removing the
-margument makes this work? I cannot see why this doesn't work, it really should? I wonder for how long this hasn't been working?
purs bundle is no more, closing 🙂