那个那个,看到最近 react 发展越发成熟了。 于是小生也开始蠢蠢欲动,便想试着用用写点小东西玩玩。 然而没想到出师未捷居然死在了 webpack 这一步。_(:з」∠)_ 不知道为何每次编译都说找不到 react 和 react-dom 求各位菊苣帮助的说……
package 如下
"devDependencies": {
"babel-core": "^6.7.7",
"babel-loader": "^6.2.4",
"babel-preset-es2015": "^6.6.0",
"babel-preset-react": "^6.5.0",
"css-loader": "^0.23.1",
"react-hot-loader": "^1.3.0",
"redux-logger": "^2.6.1",
"style-loader": "^0.13.1",
"stylus": "^0.54.5",
"stylus-loader": "^2.0.0",
"webpack": "^1.13.0"
},
"dependencies": {
"react": "^15.0.2",
"react-dom": "^15.0.2",
"react-redux": "^4.4.5",
"redux": "^3.5.2"
}
然后是 webpack 的配置:
var path = require('path')
module.exports = {
entry: './entry.js',
output: {
path: path.join(__dirname, '/dist'),
filename: 'bundle.js'
},
resolve: {
extensions: ['','js','jsx','styl']
},
module: {
loaders: [
{
test: /\.js|jsx$/,
loader: 'babel',
query:{
presets:['es2015','react']
}
},
{
test: /\.styl$/,
loader: 'style!css!stylus'
}
]
}
}
窝这边大概是通过以下方法引入 react 模块,难道不可以么??? QAQ
import React from 'react';
import { render } from 'react-dom';
运行 webpack --display-error-details 返回以下信息:
ERROR in ./~/react-dom/index.js
Module not found: Error: Cannot resolve module 'react/lib/ReactDOM' in /Users/ZZZero/rainToDo/node_modules/react-dom
resolve module react/lib/ReactDOM in /Users/ZZZero/rainToDo/node_modules/react-dom
looking for modules in /Users/ZZZero/rainToDo/node_modules
resolve 'file' or 'directory' lib/ReactDOM in /Users/ZZZero/rainToDo/node_modules/react
resolve file
/Users/ZZZero/rainToDo/node_modules/react/lib/ReactDOM doesn't exist
/Users/ZZZero/rainToDo/node_modules/react/lib/ReactDOMjs doesn't exist
/Users/ZZZero/rainToDo/node_modules/react/lib/ReactDOMjsx doesn't exist
/Users/ZZZero/rainToDo/node_modules/react/lib/ReactDOMstyl doesn't exist
resolve directory
/Users/ZZZero/rainToDo/node_modules/react/lib/ReactDOM doesn't exist (directory default file)
/Users/ZZZero/rainToDo/node_modules/react/lib/ReactDOM/package.json doesn't exist (directory description file)
[/Users/ZZZero/rainToDo/node_modules/react/lib/ReactDOM]
[/Users/ZZZero/rainToDo/node_modules/react/lib/ReactDOMjs]
[/Users/ZZZero/rainToDo/node_modules/react/lib/ReactDOMjsx]
[/Users/ZZZero/rainToDo/node_modules/react/lib/ReactDOMstyl]
@ ./~/react-dom/index.js 3:17-46
ERROR in ./~/react/react.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./lib/React in /Users/ZZZero/rainToDo/node_modules/react
resolve file
/Users/ZZZero/rainToDo/node_modules/react/lib/React doesn't exist
/Users/ZZZero/rainToDo/node_modules/react/lib/Reactjs doesn't exist
/Users/ZZZero/rainToDo/node_modules/react/lib/Reactjsx doesn't exist
/Users/ZZZero/rainToDo/node_modules/react/lib/Reactstyl doesn't exist
resolve directory
/Users/ZZZero/rainToDo/node_modules/react/lib/React doesn't exist (directory default file)
/Users/ZZZero/rainToDo/node_modules/react/lib/React/package.json doesn't exist (directory description file)
[/Users/ZZZero/rainToDo/node_modules/react/lib/React]
[/Users/ZZZero/rainToDo/node_modules/react/lib/Reactjs]
[/Users/ZZZero/rainToDo/node_modules/react/lib/Reactjsx]
[/Users/ZZZero/rainToDo/node_modules/react/lib/Reactstyl]
@ ./~/react/react.js 3:17-39
1
dearrrfish 2016-05-04 07:39:28 +08:00
试试
``` { test: /\.jsx?$/, exclude: /node_modules/, ... } ``` |
2
ZZZero OP @dearrrfish 改了试试…… 情况没有变化 Orz
|
3
Niphor 2016-05-04 15:14:06 +08:00 1
|