PureScript book Chapter 8: spago build error for React.Basic

I tried to initialize chapter 8 via spago build, but get following error:

[user@sys chapter8]$ spago build
Compiling React.Basic
Error found:
at .spago/react-basic/main/src/React/Basic.purs:1:1 - 105:75 (line 1, column 1 - line 105, column 75)

  Unable to parse foreign module:

    .spago/react-basic/main/src/React/Basic.js


    The module could not be parsed:


    ImportToken {tokenSpan = TokenPn 0 1 1, tokenLiteral = "import", tokenComment = []}



See https://github.com/purescript/documentation/blob/master/errors/ErrorParsingFFIModule.md for more information,
or to contribute content related to this error.


[error] Failed to build.

.spago/react-basic/main/src/React/Basic.js is an ES module, not CommonJS.
Do I need to install different React PureScript package versions, which conform to CommonJS, as the books still needs it? See package.dhall at the bottom for current versions.

Installed purs/spago:

[user@sys chapter8]$ spago --version
0.20.9
[user@sys chapter8]$ purs --version
0.14.9

I am cloning the vanilla master version from https://github.com/purescript-contrib/purescript-book.

Possibly related (?): After upgrading to purs/spago to 0.15 I get error "A CommonJS foreign module implementation was provided"

Any help is appreciated.

Ad 1: packages.dhall

let additions =
      { react-basic =
        { dependencies = [ "prelude", "effect", "record" ]
        , repo = "https://github.com/lumihq/purescript-react-basic.git"
        , version = "main"
        }
      , react-basic-hooks =
        { dependencies =
          [ "prelude"
          , "aff-promise"
          , "aff"
          , "console"
          , "datetime"
          , "effect"
          , "either"
          , "indexed-monad"
          , "maybe"
          , "newtype"
          , "numbers"
          , "react-basic"
          , "type-equality"
          , "unsafe-coerce"
          , "unsafe-reference"
          , "web-html"
          ]
        , repo =
            "https://github.com/milesfrain/purescript-react-basic-hooks.git"
        , version = "v6.3.0-ps-0.14"
        }
      , react-basic-dom =
        { dependencies =
          [ "prelude"
          , "effect"
          , "foreign-object"
          , "react-basic"
          , "unsafe-coerce"
          , "web-dom"
          , "web-events"
          , "web-file"
          , "web-html"
          ]
        , repo = "https://github.com/lumihq/purescript-react-basic-dom.git"
        , version = "v3.2.0"
        }
      , indexed-monad =
        { dependencies = [ "control", "newtype" ]
        , repo = "https://github.com/garyb/purescript-indexed-monad.git"
        , version = "master"
        }
      }

If you can I’d suggest you update to Purs 0.15.2 as this will use ESM everywhere - downside is of course that you’ll have to update all the common-js modules you have to ESM (and a few minor issues).


EDIT: Did not check but AFAIK the book is being converted to 0.15.2 and maybe the code got updated already.

1 Like

You are right, thanks!
The repo has been updated a week ago for 0.15 with ESM, so I simply rebased the ebook code.