Example using Reasonml for client and custom server #7326
Labels
area: examples
Anything inside the examples folder
good first issue
Easy to fix issues, good for newcomers
Feature request
Is your feature request related to a problem? Please describe.
It's not really a problem per se.
Even though the repo provides two examples, https://github.com/zeit/next.js/tree/canary/examples/custom-server-reasonml, and https://github.com/zeit/next.js/tree/canary/examples/with-reasonml, there is no example demonstrating how to use Reasonml in both the client and the server side.
Describe the solution you'd like
Providing a small, working example.
Describe alternatives you've considered
It could also be nice to have some actual documentation instead of an example.
Additional context
I tried to build a fullstack Reasonml application and ran into a bunch of problems, bugs, boilerplate, etc...
The
Promise
issueFirst of all, as noticed here, and here, when Bucklescript targets
commonjs
instead ofes6
, you will get the following error when usingPromise
:That's because, react-is (used internally by the
next-server
module) will consider that a Component usingPromise
is not a Component. Is it a bug related toreact-is
? To the waynext
uses it? Or to something else? I have honestly no clue.Notice that you don't even need to build a
Promise
in order to reproduce the bug, the simple presence of the wordPromise
will throw the infamousnot a React Component
exception.For example:
commonjs
ores6
?As you can see in the two examples linked above, the server
bsconfig.json
file targetscommonjs
, and the client config file targetses6
(for the reasons mentioned above). For the server side example, usingcommonjs
is more convenient, since targettinges6
on the server side would lead to a lot of boilerplate, involving the use ofbabel
.Also, using
babel-node
(indev
, and some properbabel
compilation inprod
) is not really an option, since it doesn't play well with the not-transpiled files located in thenode_modules
(see here).Finally, even after setting up the whole project, it will fail at runtime. Since the Reasonml bindings for
next
(I used my own bindings), and forexpress
(https://github.com/reasonml-community/bs-express), can't work for bothes6
andcommonjs
! As you can see here.Conclusion
I feel like the
Promise
issue should be solved first, it looks like a bug, and it's too "bizarre" to be ignored.That being said, there is probably a way to build a fullstack Reasonml application using Next.js right now 😄
The text was updated successfully, but these errors were encountered: