I am trying to import components from a published npm package dynamically using react-loadable. The import is successful with components located in the src/ folder. However any components that I try to import from node_modules produces the following error:
Loadable error:
Error: Cannot find module '@material-ui/core/Button'
at |groupOptions: {}|namespace object:1074:1
Code:
const Component = Loadable({
loader: () => import('@material-ui/core/Button'),
loading: () => <div>Loading...</div>,
});
Some context:
The main goal is to be able to pass a import path (in src/ or node_modules) string to loadable and have loadable import the component (and do code splitting).
If this is not possible with react-loadable, any suggestions are welcome. Thanks in advance.