How to use Js_List in browser?

Hi,
I noticed at the top of the generated js file:

import * as Js_list from "rescript/lib/es6/js_list.js";

This leads to an error in the browser:

Uncaught TypeError: Failed to resolve module specifier "rescript/lib/es6/js_list.js". Relative references must start with either "/", "./", or "../".

I see rescript/lib/es6/js_list.js is in node_modules, but bare import specifiers aren’t supported in browsers, according to this stackoverflow answer

Should I avoid using Js_list?

ReScript compiles to file paths that are only suitable for local development in a NodeJS environment, so I’d recommend a development server / bundler that understands ES6 modules. E.g. ViteJS / webpack are designed to bundle webapps that can be deployed for browser consumption.

You can also check out esbuild & rollup for straightforward bundling.

Here’s a repo that show-cases bundling with esbuild: GitHub - bobzhang/rescript-repack-demo: A demo to show how to package high quality ReScript libraries for JS users

3 Likes

Isn’t es6-global what you would need to avoid bundling? It even says so in the docs:

  • "module": "es6-global" resolves node_modules using relative paths. Good for development-time usage of ES6 in conjunction with browsers like Safari and Firefox that support ES6 modules today. No more dev-time bundling!

Either that, or a bundler as you said :smiley:

2 Likes

Yeah, unfortunately there’s so many problems with bundler less setups that I don’t even want to recommend it here…

2 Likes

What should people beware of (in the context of playing around or prototyping)?

3 Likes