spago icon indicating copy to clipboard operation
spago copied to clipboard

Failed to run a JS file when spago bundle-app with purescript-unordered-collections

Open kalxd opened this issue 4 years ago • 4 comments

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.

kalxd avatar Dec 05 '21 08:12 kalxd

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")])

klntsky avatar Dec 05 '21 13:12 klntsky

great, purs bunlde works. thanks a lot.

kalxd avatar Dec 06 '21 12:12 kalxd

I think we should not close this yet.

klntsky avatar Dec 07 '21 18:12 klntsky

Yeah, I think this is some sort of bug? The result is indeed really puzzling:

  • spago bundle-app is a thin layer over purs bundle "output/*/*.js" -m Main --main Main -o index.js
  • running that command still results in the failure, but removing the -m argument makes this work? I cannot see why this doesn't work, it really should? I wonder for how long this hasn't been working?

f-f avatar Dec 08 '21 00:12 f-f

purs bundle is no more, closing 🙂

f-f avatar Sep 29 '23 21:09 f-f