Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example using Reasonml for client and custom server #7326

Closed
gaku-sei opened this issue May 14, 2019 · 3 comments
Closed

Example using Reasonml for client and custom server #7326

gaku-sei opened this issue May 14, 2019 · 3 comments
Labels
area: examples Anything inside the examples folder good first issue Easy to fix issues, good for newcomers

Comments

@gaku-sei
Copy link

gaku-sei commented May 14, 2019

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 issue

First of all, as noticed here, and here, when Bucklescript targets commonjs instead of es6, you will get the following error when using Promise:

The default export is not a React Component in page: ***

That's because, react-is (used internally by the next-server module) will consider that a Component using Promise is not a Component. Is it a bug related to react-is? To the way next 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 word Promise will throw the infamous not a React Component exception.

For example:

console.log(typeof Promis); // works
console.log(typeof Promise); // fails: The default export is not a React Component in page: ***

commonjs or es6?

As you can see in the two examples linked above, the server bsconfig.json file targets commonjs, and the client config file targets es6 (for the reasons mentioned above). For the server side example, using commonjs is more convenient, since targetting es6 on the server side would lead to a lot of boilerplate, involving the use of babel.

Also, using babel-node (in dev, and some proper babel compilation in prod) is not really an option, since it doesn't play well with the not-transpiled files located in the node_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 for express (https://github.com/reasonml-community/bs-express), can't work for both es6 and commonjs! 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 😄

@Timer Timer added good first issue Easy to fix issues, good for newcomers help wanted area: examples Anything inside the examples folder labels Jun 14, 2019
@Kacppian
Copy link

I could probably take a shot at this?

@Timer
Copy link
Member

Timer commented Apr 15, 2020

Closing as stale and lack of demand. If someone creates an example, feel free to send a PR.

@Timer Timer closed this as completed Apr 15, 2020
@balazsorban44
Copy link
Member

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@vercel vercel locked as resolved and limited conversation to collaborators Jan 30, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: examples Anything inside the examples folder good first issue Easy to fix issues, good for newcomers
Projects
None yet
Development

No branches or pull requests

4 participants