I'm trying to implement the React Context API in my Nextjs app using ReasonReact but getting caught out by the bucklescript compiler's way of inferring module names.
To make the context available to the whole tree I need to inherit from the Nextjs App component. The problem is that Next looks by convention for pages/_app.js
for App component inheritance, but when I use _app.re
for the filename, bsb
doesn't produce a Reason module named "App".
In fact, bsb
prints the following message and ignores the file:
IGNORED: file _app.re under pages is ignored because it can't be turned into a valid module name. The build system transforms a file name into a module name by upper-casing the first letter
Is there some way to tell Nextjs to look elsewhere for the App component? Or perhaps a way to tweak bsb
for just this one file?
That last one seems like a long shot but I don't want to dip into javascript unless I really have to.
One possible solution is to add a js file with an appropriate name that re-exports from a compiled module with a name that BuckleScript does support:
// _app.js
export { default } from './next_app.bs.js';
I had to do this to get certain features working with Gatsby. See this example.