老师使用webpack打包提示找不到模块react
来源:7-5 webpack--entry、output
可以说很强了
2017-12-23
import React,{Component} from 'react';
import ReactDOM from 'react-dom';
import {fn2} from './util'
class Demo extends Component{
render(){
fn2();
return (
<div className="box">{this.props.text}</div>
);
}
}
ReactDOM.render(
<Demo text="This is a test"/>,
document.querySelector(".container")
)ERROR in ./src/script/index.js
Module not found: Error: Can't resolve 'react' in 'F:\nodejs\building\src\script'
@ ./src/script/index.js 5:13-29
ERROR in ./src/script/index.js
Module not found: Error: Can't resolve 'react-dom' in 'F:\nodejs\building\src\script'
@ ./src/script/index.js 9:16-36
都已经安装好了babel-loader,babel-preset-react也安装了
const path=require('path')
module.exports={
entry:{
index:'./src/script/index.js'
},
output:{
path:path.resolve(__dirname,'build/script'),
filename:'[name].js'
},
module:{
rules:[
{
test:/\.js$/,
include:[path.resolve(__dirname,'src/script')],
loader:'babel-loader'
}
]
}
}写回答
1回答
-
Samaritan
2017-12-28
看一下你根目录node_module 里确实有 react 吗
00
相似问题