export {
loader$1 as loader,
make,
$$default as default,
}
This is the final output generated by Rescript.
When I changed the js file to export const loader = XXX, export default XXX
It started up normally when running in dev mode using the React Router CLI.
module Inner = {
let loader = async () => Console.log("inner")
}
let loader = async () => Console.log("toplevel")
e.g. this compiles to
async function loader() {
console.log("inner");
}
let Inner = {
loader: loader
};
async function loader$1() {
console.log("toplevel");
}
export {
Inner,
loader$1 as loader,
}
maybe you can restructure your code so that the compiler emits it without aliases. In the example above for instance by moving the Inner loader to a separate file.
I tried writing a vite transformation plugin to enable code written in ReScript to run properly in SSR mode with React Router v7 in Vite. However, I still haven’t found the reason why it doesn’t support the error caused by export { someVariable as default } .
But it seems to be working properly now.
// vite.config.js
import { reactRouter } from "@react-router/dev/vite";
import tailwindcss from "@tailwindcss/vite";
import { defineConfig } from "vite";
import rewrite from './vite-plugin-fix-export-default'
export default defineConfig({
plugins: [tailwindcss(), rewrite(), reactRouter(), ]
});
input
origin: // Generated by ReScript, PLEASE EDIT WITH CARE
import * as JsxRuntime from "react/jsx-runtime";
function loader() {
return Promise.resolve({
text: "about 1"
});
}
function About$default(props) {
return JsxRuntime.jsx("strong", {
children: props.loaderData.text
});
}
let $$default = About$default;
export {
loader,
$$default as default,
}
/* react/jsx-runtime Not a pure module */
output:
result: // Generated by ReScript, PLEASE EDIT WITH CARE
import * as JsxRuntime from "react/jsx-runtime";
function loader() {
return Promise.resolve({
text: "about 1"
});
}
function About$default(props) {
return JsxRuntime.jsx("strong", {
children: props.loaderData.text
});
}
let $$default = About$default;
export { loader };
export default $$default;
/* react/jsx-runtime Not a pure module */
It’s tricky to work around, but the rescript doc site is using react router v7 with loaders and HMR works for the most part. There are a lot of files with multiple components that can be broken up, but changes to loaders works.
It would be nice to have exports live next to the value instead of all exported at the end as an object.