gpt4 book ai didi

javascript - 找不到模块 :Can't resolve './components/counter' in 'C:/...demo\counter-app\src'

转载 作者:行者123 更新时间:2023-12-02 21:16:09 28 4
gpt4 key购买 nike

我对 React 完全陌生,我正在 YouTube 上学习教程(使用 MOSH 编程),但我遇到了这个错误,在找到类似问题后无法解决。

index.js

import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import * as serviceWorker from './serviceWorker';
import "bootstrap/dist/css/bootstrap.css";
import Counter from './components/counter';
//import * as Counter from './components/counter'; //tried this method too

ReactDOM.render(
<Counter />,
document.getElementById('root')
);

// If you want your app to work offline and load faster, you can change
// unregister() to register() below. Note this comes with some pitfalls.

serviceWorker.unregister();

计数器.jsx

import React, { Component } from 'react';

class Counter extends Component {

render() {
return <h1> Hello world</h1>;
}
}

export default Counter;

在命令提示符下,我在删除 package-lock.json 后完成了 npm installnpm start 但仍然出现相同的错误

文件夹结构enter image description here

提前致谢。

最佳答案

将您的组件文件夹移至 SRC 内,这将修复该问题

关于javascript - 找不到模块 :Can't resolve './components/counter' in 'C:/...demo\counter-app\src' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60965763/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com