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

Unable to run using Next.js #44

Open
zenorocha opened this issue Sep 24, 2021 · 2 comments
Open

Unable to run using Next.js #44

zenorocha opened this issue Sep 24, 2021 · 2 comments

Comments

@zenorocha
Copy link

I was able to run Firepad successfully using plain React, but unfortunately, I couldn't execute it using Next.js

Here's a running example without Firepad:
https://codesandbox.io/s/react-moncao-editor-nextjs-without-firepad-u8p4k

And here's what happens when you import the package:
https://codesandbox.io/s/react-moncao-editor-nextjs-with-firepad-4ny9s

It would be amazing if we could get this fixed.

@Shubham567
Copy link

Editor Not working, Use

The problem which you demonstrated is not actually with firepad, but monaco-editor.
Problem is NextJs is trying to do SSR, where it fails, as there is restriction of importing global CSS only from _app.js, There are a few legacy plugins for webpack which deals with this issue. But there is a better library which deals with it in a much better way.

https://www.npmjs.com/package/@monaco-editor/react

Above will get your editor running. But

There is problem in current implementation of firepad and it still wont support NextJs.

Right now firepad implementation has monaco-editor as a peer dependency, which is problematic to use with NextJs, (issue which you faced rn).

Currently firepad uses monaco instance by directly importing global monaco-editor as dependency, To make it work we need to be able to pass monaco instance to fromMonaco method circumvent this problem, which will require a big rewrite. @Progyan1997 can tell whether if that will be a viable option.

There might be another solution with webpack, Things to keep in mind that Next 11 has now moved to webpack 5 but Next10 is and older still remain very popular till date. I am not a webpack expert to be able to figure that out.

I too faced same issue, I had to move quickly with the project, so I choose to create a Reactjs project and import it using just used an iframe to render it inside my NextJs project, with interframe communication. Its almost imperceptible except for some unwanted reloads when I change language.

Here is the React implementation which I use inside iframe. https://cpd.skillcounty.com?lang=python

@0xTheProDev
Copy link

Hi @zenorocha, as @Shubham567 already mentioned you need to a bit of hardlifting to get monaco work with NextJS.
To address the second concern, you have couple of options you might want to try to circumvent the requirement of monaco-editor package directly from Firepad.
One is to alias it in Webpack Config using resolve.alias property, or if you are having a TypeScript package use paths in tsconfig.json.
Or you can perform some pre-build transformation to modify the import statement into one that helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants