Reactjs React-won';t导入我的模块“;未找到模块:Can';“t解决”;
React没有将我的组件导入到YouTubeApp.js中。 这看起来很傻,我的react应用程序中还有其他组件,我可以毫无问题地导入,但这一个组件我无法导入 Github: 另外,YouTubeApp.js当前导入到my index.js中,没有任何问题。我正在使用index.js和links中导入的react路由,并成功地将链接路由到YouTubeApp.js。当我尝试将任何组件导入YouTubeApp.js时,出现了无法解决“component name”错误,如果不导入任何组件,YouTubeApp.js工作正常 我已经验证了正确的路径,组件的名称 YouTubeApp.jsReactjs React-won';t导入我的模块“;未找到模块:Can';“t解决”;,reactjs,Reactjs,React没有将我的组件导入到YouTubeApp.js中。 这看起来很傻,我的react应用程序中还有其他组件,我可以毫无问题地导入,但这一个组件我无法导入 Github: 另外,YouTubeApp.js当前导入到my index.js中,没有任何问题。我正在使用index.js和links中导入的react路由,并成功地将链接路由到YouTubeApp.js。当我尝试将任何组件导入YouTubeApp.js时,出现了无法解决“component name”错误,如果不导入任何组件,YouT
import React from 'react';
import Other from './components/other';
class YouTubeApp extends React.Component {
render() {
return (<p>test</p>
);
}
}
export default YouTubeApp;
从“React”导入React;
从“./组件/其他”导入其他;
类YouTubeApp扩展了React.Component{
render(){
返回(test
);
}
}
导出默认YouTubeApp;
这是我要导入的组件:
import React from 'react';
class Other extends React.Component {
render() {
return (
<div clasNames="ui container">test!</div>
);
}
}
export default Other;
从“React”导入React;
类其他扩展React.Component{
render(){
返回(
测试!
);
}
}
出口违约其他;
我需要将更多组件至少嵌套几层,但这个问题仍然存在。查看GitHub存储库,YouTubeApp.js和other.js似乎都在“components”目录中。因此,在YouTubeApp.js(或“组件”目录中的任何其他组件)中,您的导入应该是:
import Other from './other';
显示目录结构。例如,如果第一个脚本是
src/YouTubeApp.js
,那么您试图包含src/components/other.js
或src/components/other/index.js
。难道other
没有js扩展吗<代码>从“./组件/其他”导入其他代码>谢谢你的回复。事实上,我发现我在添加一个额外的文件夹,我把它改成了“/other”,结果它成功了。我觉得自己太傻了,哈哈。谢谢瑞安,就这样。伙计,我太复杂了,以为还有别的事!谢谢你的帮助!