React 报错:Module not found: Can't resolve 'antd' in

就这么个小页面,导入 antd,编译就报错!(消耗长时间编译)
`

./src/pages/demo/Life.jsModule not found: Can't resolve 'antd' in 'E:\ReactAntd\reactantd\src\pages\demo'

`

报错1:Module not found: Can't resolve 'antd' in
报错2:JavaScript heap out of memory

删除导入的 antd 和 antd.css 就没问题了。
删除了node_modules,重新install,没用。

`import React from 'react';
import {Button} from 'antd';
import 'antd/dist/antd.css';
import './index.css';

export default class Life extends React.Component{

constructor(props) {
    super(props);
    this.state = {
        count: 0
    };
}

handleAdd=()=>{
    this.setState({
        count: this.state.count + 1
    })
}

handleClick(){
    this.setState({
        count: this.state.count + 1
    })
}

render(){

    return <div className="content">
        <p>React生命周期</p>
        <Button onClick={this.handleAdd}>and 点击一下</Button>

    </div>
}

}`

阅读 21.3k
2 个回答

看下你的 package.json 里面有没有 antd, 如果有的话. 你重新启动一下项目试试~

npm install antd --save

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题