[英]cannot find module in index.js
hi I have this error while trying to import components (im using flow type)您好我在尝试导入组件时遇到此错误(我使用流类型)
This is my ReloadScreenPayLater.component.js这是我的 ReloadScreenPayLater.component.js
/** * Reload Screen Component * @param {Props} onReload - reload Parameter * @return {React.Node} - return react component */ const ReloadScreenPaylater = ({ onReload }: Props): React.Node => ( <ReloadScreen onReload={onReload} /> ); ReloadScreenPaylater.displayName = config.displayName; export default ReloadScreenPaylater;
this is my export in./src/Components/ReloadScreenPayLater/index.js when i highlight the export it shows the ReloadScreenPayLater.component.js这是我在 ./src/Components/ReloadScreenPayLater/index.js 中的导出 当我突出显示导出时它显示 ReloadScreenPayLater.component.js
so when i tried to run the apps or snap test it shows this error所以当我尝试运行应用程序或快照测试时,它会显示此错误
src/Screens/InOutPayLater/InOutPayLater.component.snap.test.js ● Test suite failed to run Cannot find module '../../Component/ReloadScreenPayLater' from 'src/Screens/InOutPayLater/InOutPayLater.component.snap.test.js' 10 |.mock('../../Components/InOutEmptyState', () => 'InOutEmptyState') 11 | > 12 |.mock('../../Component/ReloadScreenPayLater', () => 'ReloadScreenPayLater');
what i want to achieve is to be able to import the component from this path '../../Component/ReloadScreenPayLater'我想要实现的是能够从此路径导入组件 '../../Component/ReloadScreenPayLater'
nb: it works just fine if import like this注意:如果像这样导入它就可以正常工作
import ReloadScreenPaylater from '../../Components/ReloadScreenPayLater/ReloadScreenPayLater.component';
For default export (ie export default ReloadScreenPaylater =...
), we should use this import style instead.对于默认导出(即
export default ReloadScreenPaylater =...
),我们应该改用这种导入样式。
import ReloadScreenPaylater from '../../Components/ReloadScreenPayLater/ReloadScreenPayLater.component';
For named export (ie export const ReloadScreenPaylater =...
), then we should use the other named import style.对于命名导出(即
export const ReloadScreenPaylater =...
),那么我们应该使用其他命名导入样式。
import { ReloadScreenPaylater } from '../../Components/ReloadScreenPayLater/ReloadScreenPayLater.component';
From ES6 and onwards, you need to get the default exports from their name instead of {default}从 ES6 及以后的版本开始,您需要从它们的名称而不是 {default} 获取默认导出
Use this:用这个:
import ReloadScreenPaylater from '../../Components/ReloadScreenPayLater/ReloadScreenPayLater.component';
Or if you have named export then use import { Exported Named Component } from 'path'
或者,如果您已命名 export 则使用
import { Exported Named Component } from 'path'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.