Can't find variable: require

Sorry for the (probably) silly question; I am trying to cut my teeth with PureScript building a very simple application.

I have managed to create a simple project that compile correctly, but when I try to load the bundled script in the browser I get the “Can’t find variable: require” error.

I suppose I am doing something wrong in the PRNG FFI module, but I am not able to spot what.
The project is available here: https://github.com/clipperz/password-generator/tree/develop

Any hint at what I’m doing wrong?

Thanks,

Giulio Cesare

I’d guess it’s referring to the function ‘require’ which implements the CommonJS module system. The web browser doesn’t implement that module system, so you need to preprocess your code to remove those. Webpack and Rollup and Parcel all do that. I heard Parcel is the easiest because it has reasonable defaults and heuristics. I don’t have a link to an example project right now, but I know there are some on GitHub that include this preprocess step in their build script (maybe defined in package.json or similar) that might help you get started with that.

This is also relevant, but I’m not sure if it still works:

1 Like

Ok; I’ll give Parcel a try and as see how far I can get.
Thanks!

I confirm that post-processing the index.html file with Parcel fix my problem.
I now have to sort out how to wrap everything nicely into the project structure, but at least I know which way to dig; thanks @chexxor.

It now works! :slight_smile:

1 Like