Open mudkipdev opened 2 years ago
Hi @mudkipdev, could you try using the alpha release of react-blockly instead? 7.0.0-alpha.2
is the latest right now, and it's got a substantially different build system from the 6.x series. It may fix your problem - please let me know if it does!
No it doesn't, i have the same issue
I have found a solution: As the library is only rendered on the client, you can disable server-side-rendering with next.js dynamic import:
const BlocklyWorkspace = dynamic(
() => import('react-blockly').then((mod) => mod.BlocklyWorkspace),
{ ssr: false }
)
This works for me on next.js 12
Aha, that makes sense. I don't know much about Next.js myself (I've never tried using it), but if there's a way for me as a library author to tell Next.js to never try to render this component on the server side, I'd be happy to add that. Thanks @Entkenntnis for figuring out the workaround!
Hey ! Was wondering if anyone has made any more progress on this issue. @Entkenntnis's solution works well, but it fails when trying to build the app (e.g. with npm run build) As well, I wasn't able to adapt it to useBlocklyWorkspace
@loicfrnt My final solution was to ignore react-blockly and inject blockly directly. I have reused code that was relevant for me and added other stuff that this package is missing (e.g. auto-resize, locale, etc..)
you can take a look at my implementation: https://github.com/Entkenntnis/robot-karol-online/blob/main/components/ide/BlockEditor.tsx
no problems with building and export in next.js
Edit: updated file url
A year after this issue has been closed, but just in case anyone else comes looking -- this is specifically a problem operating under Next.js. The easiest solution to this problem is to add react-blockly
to transpilePackages
in your next.config.js
(or wherever you configure Next.js.
Whenever I import BlocklyWorkspace I get an error saying "SyntaxError: Cannot use import statement outside a module". I am using Next.js with create-next-app.
My code:
Call Stack