React项目npm start编译失败:Module not found问题求助
我在谷歌搜索过该错误,尝试了诸多建议和解决方案,但均不适用于我的情况。使用Node运行React应用,执行npm start后出现编译失败提示:
Module not found: Error: Can't resolve './componentes/Topo' in 'C:\Users\filip\Documents\Filipe\1 - Front-End\React\missao-front-end-loja-de-oculos\src'
ERROR in ./src/App.js 4:0-38
Module not found: Error: Can't resolve './componentes/Topo' in 'C:\Users\filip\Documents\Filipe\1 - Front-End\React\missao-front-end-loja-de-oculos\src'
项目路径结构
项目根目录:C:\Users\filip\Documents\Filipe\1 - Front-End\React\missao-front-end-loja-de-oculos
相关文件代码
./public/index.html
<!DOCTYPE html> <html lang="pt-br"> <head> <meta charset="utf-8" /> <link rel="icon" href="%PUBLIC_URL%/favicon.ico" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <meta name="theme-color" content="#000000" /> <link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" /> <link rel="manifest" href="%PUBLIC_URL%/manifest.json" /> <title>Óticas vida - Loja de óculos</title> </html>
./src/App.js
import Topo from './componentes/Topo'; import Conteudo from './componentes/Conteudo'; import Rodape from './componentes/Rodape/'; function App() { return ( <div> <Topo /> <Conteudo /> <Rodape /> </div> ); } export default App;
./src/componentes/conteudo/index.js
import SecaoCapa from '../componentes/SecaoCapa'; import SecaoSobre from '../componentes/SecaoSobre'; import SecaoProdutos from '../SecaoProdutos'; import SecaoContato from '../SecaoContato'; export default function Conteudo() { return ( <main> <SecaoCapa /> <SecaoProdutos /> <SecaoSobre /> <SecaoContato /> </main> ) }
./src/componentes/Topo/Topo.js
export default function Topo() { return ( <header> <div> <img src='public\assets\logo.png' alt='imagem de um óculos à direita e o nome da ótica à esquerda' /> <nav> <a href='#produtos'>PRODUTOS</a> <a href='#sobre'>SOBRE</a> <a href='#contato'>CONTATO</a> </nav> </div> </header> ) }
已尝试的解决方法
- 尝试使用yarn时出现权限错误:
yarn : The file C:\Users\filip\AppData\Roaming\npm\yarn.ps1 cannot be loaded because the script execution was
disabled on this system. For more information, see about_Execution_Policies at
https://go.microsoft.com/fwlink/?LinkID=135170.
On line:1 character:1
- yarn
🇧🇷
- CategoryInfo : SecurityError: (:) [], PSSecurityException
- FullyQualifiedErrorId : UnauthorizedAccess
- 删除
package-lock.json后重新安装依赖,无效果; - 执行
npm cache clean --force后运行npm install,问题依旧。
我怀疑是路径配置问题,但尚未找到问题所在,作为新手需要指导,请问该如何解决此问题?谢谢。
内容的提问来源于stack exchange,提问作者Oliveira

