-
Notifications
You must be signed in to change notification settings - Fork 26
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
Import component dynamically. WebpackError: TypeError: Cannot read property 'call' of undefined #4
Comments
The link you posted to your repo cannot be build because it uses data from Contentful. It is hard to tell what could be going on without a minimal repo to reproduce the error. |
oh sorry, you're right. |
Maybe it's best if you switch to JSON data source in a different branch. |
Ok, so i created a new branch on Here is the link: Thanks for your time, i appreciate it 🙏🏻 |
I spent almost the whole day yesterday trying to figure out what the problem is. I tried debugging gatsby's build process. There seems to be some problem with how the modules are loaded, but I can't figure out exactly what. It would be really helpful to find what version of gatsby was still working, but when I tried |
Ok, thats weird.. now it doesn´t work for me either. I did some testing, maybe its helping: (The file, where everything works fine: https://github.com/nkosakul/pepita/blob/test/yarn.lock) I´m super confused |
Ok, that Adding the resolution below in
Now I only need to figure out what has changed between the two version of babel. |
I´m glad that helped! And thank you! This fix seems to fail at the first build, when there is no So for me, netlify will still fail to deploy. |
I am getting this same error.
I am also using contentful to source data and getting error on build-html process of |
Any hope for getting this resolved? I'm also experiencing the error... Versions installed: |
We are getting this same error. We are using WordPress as our data source, but the code looks exactly the same as what was posted. Using latest versions. Anybody have any insight to this issue outside of what has already been posted? |
Same for me. I tried taking a fork of the repo and updating the dependencies but it did not help. (was hoping for an easy win!) |
Looks like this issue in the main repo is related; gregberge/loadable-components#599 The only way I managed to get around this was by removing the dynamic imports - basically, instead of passing the component name/path as a string I write the whole |
any news? |
Could you please explain a bit more about "I write the whole loadable(() => import and pass that instead." |
So instead of `<DynamicLoader file=“filename”>` I ended up writing something like `<DynamicLoader loadable={loadable(() => import(‘path/to/filename’)}>`
Don’t know how helpful that would be for you, it’s not as clean as what we’d like but it works. Basically you hardcode the loadable components and dynamically select them instead of using a dynamic import.
|
I've found another workaround. Wrapper for dynamic component like this: import React from 'react';
import loadable from '@loadable/component';
const ProxyComponent = (props) => {
const Loaded = loadable(() => import('./Component'));
return <Loaded {...props} />;
}
export default ProxyComponent A map for component list: import ProxyComponent from './ProxyComponent';
//...other imports
export default {
'ProxyComponent': ProxyComponent,
//...other components
}; And eventually use this map where I need this dynamic component: const componentName = 'ProxyComponent';
const SomeDynamicComponent = proxyMap[componentName];
return (
...
<SomeDynamicComponent />
...
); It works in SSR as a static and in SPA as a dynamic. |
Hello Everyone, I solved this problem by adding the following condition: let DynamicModule = null;
const windowGlobal = typeof window !== 'undefined' && window;
if (windowGlobal){
DynamicModule = loadable((props) => import(`../components/${props.module}`));
} and before calling this module, check if DynamicModule exists : {
DynamicModule && <DynamicModule module={`your module name`} />
} I hope this help |
Same issue here, I'm only loading icons so for now I'm just ignoring the icons during SSR import React, { useEffect } from 'react';
import loadable from '@loadable/component'
import PropTypes from 'prop-types';
const Icon = ({ icon, ...rest }) => {
if(typeof(window) === 'undefined' || !window) return "";
const Comp = loadable(() => import(`./set/${icon}`))
return <Comp {...rest} />
}
Icon.propTypes = {
icon: PropTypes.string.isRequired,
color: PropTypes.string.isRequired,
}
export default Icon; |
I'm getting the same error here with |
Hi!
First, thanks for the plugin! Really cool!
I´m using
@loadable/component
for a portfolio website with Gatsby + Contentful.Its working great with Gatsby version
2.20.36
, but as soon as i update Gatsby to2.20.4
or higher, which i do because of the incremental build feature i want to use, its failed on build.I´m using
gatsby-plugin-loadable-components-ssr
v2.0.0
The Error i get is
WebpackError: TypeError: Cannot read property 'call' of undefined
.The Error comes up, while gatsby is building the html pages
My Code:
gatsby-config.js looks like this
I´m new to gatsby and its my first time using it with contentful, so sorry if its a dumb question.
Here is also the link to my repo
https://github.com/nkosakul/pepita/tree/develop
The text was updated successfully, but these errors were encountered: