TypeError: Cannot call a class as a function

Everything works fine on localhost by running npm run dev.
But I got this error on the server: TypeError: Cannot call a class as a function.
I can duplicate this error by running npm run build and run npm run serve


Can anyone help me please?

1 Like

I have the same issue. I’ve done some major changes and only noticed this in deployment. I mainly changed to using loadable and basically updated all my packages. So finding the bug at this point would be hell. Don’t know where to start.

I narrowed it down to my “react-scroll” components. For some reason this does not want to go through the build process. It may be different in your case. Anyways, it was working before I updated all the libs, so … weird.

@tibor.udvari You’re right.
I commented out codes which are using react-scroll and it worked. It seems like react-scrolling is conflicting on server side rendering.
So I think the solution is to code scroll to element using Javascript without using this module.
You comments helped me a lot. Thank you!

@tibor.udvari I tried converting react-scroll into vanilla javascript and it didn’t solve the problem.
I think this is something resolved by frontity webpack configuration for bundling…

I just had the same thing, I left it completely out of my code for now. It might have something to do with the window, are you using window.scrollTo in your code?

I tried using anchor link smooth scroll instead. I had the same issue. I think it’s something to do with the wondow object. GitHub - mauricevancooten/react-anchor-link-smooth-scroll: React component for anchor links using the smooth scroll polyfill.

Actually I don’t think this is because of react-scroll, I think this is something happened in frontity’s webpack when building for production.
So I just set the environment variable to build for development mode.
FRONTITY_BUILD_DEVELOPMENT=true.
We may need support from Frontity team for this.

Hi @nuttawitpanyason

Welcome to the Community!

Can you please provide a repo or code-sandbox with your code? This is especially helpful to find solutions to technical issues with specific code

Detailing the info suggested here when having issues will help the community to provide the best possible help as quickly and as efficiently as possible.