简体   繁体   English

在 index.js 中找不到模块

[英]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 它有 ReloadScreenPayLater

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.

相关问题 nodemon 找不到模块&#39;/path/to/project/home/index.js&#39; - nodemon Cannot find module '/path/to/project/home/index.js' 电子找不到模块/resources/app/index.js - Electron Cannot find module /resources/app/index.js 错误:index.js: [BABEL]: 在 react-native 中找不到模块 'node:fs' - error: index.js: [BABEL]: Cannot find module 'node:fs' in react-native 汇总别名和 Jest:无法从 'src/index.js' 中找到模块 'global/http' - Rollup aliases and Jest: Cannot find module 'global/http' from 'src/index.js' 存储库推送尝试到 railway.app 后找不到模块“/workspace/index.js”错误 - Cannot find module '/workspace/index.js' error after repository push attempt to railway.app 错误:找不到模块“C:\Users\rodri\nodejs_paypal\src\index.js” - Error: Cannot find module 'C:\Users\rodri\nodejs_paypal\src\index.js' index.js:找不到模块“react-native-reanimated/plugin” - index.js: Cannot find module 'react-native-reanimated/plugin' module.js:491 抛出错误; 错误:找不到模块“www/node-str/index.js” - module.js:491 throw err; Error: Cannot find module 'www/node-str/index.js' 模块构建失败(来自 ./node_modules/babel-loader/lib/index.js):错误:找不到模块“./src/data” - Module build failed (from ./node_modules/babel-loader/lib/index.js): Error: Cannot find module './src/data' ./index.js 被识别为一个模块 - ./index.js is recognized as a module
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM