Error when importing react-konva in nextjs
See original GitHub issueSo my error message is this
Error: require() of ES Module /app/node_modules/konva/lib/Core.js from /app/node_modules/react-konva/lib/ReactKonvaCore.js not supported. Instead change the require of Core.js in /app/node_modules/react-konva/lib/ReactKonvaCore.js to a dynamic import() which is available in all CommonJS modules.
Not quite the same as with #588 and the fixes suggested there (dynamic loading of components with ssr disabled) Seem to do nothing for me.
I did this for my app component:
import React from 'react';
import dynamic from 'next/dynamic';
import { wrapper } from '../stores';
import '../styles/globals.css';
import MainLayout from '../components/layouts/mainLayout';
import AuthLayout from '../components/layouts/authLayout';
const layouts = {
default: MainLayout,
auth: AuthLayout,
};
// eslint-disable-next-line react/prop-types
const PortalApp = function ({ Component, pageProps }) {
// eslint-disable-next-line react/prop-types
const { layout } = Component;
switch (layout) {
case 'auth':
return React.createElement(layouts.auth, null, <Component {...pageProps} />);
default:
return React.createElement(layouts.default, null, <Component {...pageProps} />);
}
};
export default dynamic(() => Promise.resolve(wrapper.withRedux(PortalApp)), {
ssr: false,
});
But I still get the error. Not sure what do to here or how to fix this.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:16 (6 by maintainers)
Top Results From Across the Web
Error when importing in Next.js · Issue #588 · konvajs ... - GitHub
I installed konva and react-konva to my next.js project. When I try to import anything from the react-konva package, I get this error....
Read more >Nextjs & konva error I'm not sure how to resolve - Reddit
So I'm trying to add some canvas to my app to display dotted lines between points on the screen and I figured react-konva...
Read more >next.js - ESM packages (konva) need to be imported. Use ...
I get the following error when importing Html from react-konva-utils. I have tried importing this using a dynamic import and just by ...
Read more >Getting started with react and canvas via Konva
react -konva is a JavaScript library for drawing complex canvas graphics using React. It provides declarative and reactive bindings to the Konva Framework....
Read more >react-konva - npm
React binding to canvas element via Konva framework. Latest version: 18.2.3, last published: 2 months ago. Start using react-konva in your ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@ein1x3x make sure
react
,react-dom
andreact-konva
versions are matched.17.x
or18.x
Same problem here 👍. I tried to import it dynamically either inside and outside the stage component.
Current code causing problems:
Definition:
Usage: