How to handle `cannot find module`
See original GitHub issueI am using string literals to dynamically import components based off text entered into my CMS. In the case that the user enters text for a component that does not exist, id love to be able to fallback.
In the below code i have tried using an ErrorBoundary, fallback of null
, and a try/catch block, but i still get the ‘Error: Cannot find module’ error.
const ActualIcon = ({ icon }) => {
try {
const Icon = loadable(() => import(`../Icons/elements/${icon}`), {
fallback: null,
});
return <Icon />;
} catch (e) {
return null;
}
};
const FeatureIcon = ({ icon }) => (
<ErrorBoundary>
<ActualIcon icon={icon} />
</ErrorBoundary>
);
Is there some other way i can prevent this error when trying to use loadable on a component that doesnt exist?
Issue Analytics
- State:
- Created 4 years ago
- Comments:5
Top Results From Across the Web
How do I resolve "Cannot find module" error using Node.js?
This error can be encountered if you are require ing a module that has a missing or incorrect main ...
Read more >How to resolve "Cannot find module" error in Node - Sabe.io
The issue is that Node is unable to find the module that you are trying to import into your Node application. The most...
Read more >Cannot find module 'X' error in Node.js | bobbyhadz
To solve the "Cannot find module" error in Node.js, make sure to install the package from the error message if it's a third-party...
Read more >How to resolve can't find module error in Node.js - Reactgo
To fix Cannot find module errors, install the modules properly by running a npm install command in the appropriate directory as your project's ......
Read more >How to fix npm cannot find module error - Nathan Sebhastian
The cannot find module error occurs because npm cannot find the module required by the index.js file. In this case, the axios module....
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
@foglerek thanks for your help. The solution appears to be:
otherwise the fallbackComponent is always rendered even if there is a successful import 😃
Hey @haxxxton,
I’m having the same issue, did you manage to find a solid solution? If so, could you please share.
Thanks, David