我一直在使用反应,现在想用webpack尝试.
这是我的webpack.config.js
:
var path = require('path'); module.exports = { entry: './app.js', output: { path: path.resolve(__dirname, "build"), publicPath: "/", filename: "bundle.js" }, module: { loaders: [ { test: /\.js?$/, exclude: /node_modules/, loader: 'babel-loader', query: { presets: ['react', 'es2015'] } } ] }, resolve: { extensions: ['', 'js', 'jsx'] } }
发生的错误如下:
ERROR in ./~/react/react.js Module not found: Error: Cannot resolve 'file' or 'directory' ./lib/React in /Users/username/path/to/app/node_modules/react @ ./~/react/react.js 3:17-39
当我通过使用var React = require('react')
或导入反应到我的文件时发生此错误import React from 'react';
我安装了babel所需的预设包:
"devDependencies": { "babel-core": "^6.4.0", "babel-loader": "^6.2.1", "babel-preset-es2015": "^6.3.13", "babel-preset-react": "^6.3.13", "webpack": "^1.12.10", "webpack-dev-server": "^1.14.0" }, "dependencies": { "highcharts-release": "^4.2.1", "immutable": "^3.7.6", "react": "^0.14.5", "react-highcharts": "^6.0.0", "react-redux": "^4.0.6", "redux": "^3.0.5" }
谢谢!
根据您的引擎收录例子,你可以看到的WebPack正在寻找React
,Reactjs
或Reactjsx
不React.js
:
/Users/bIgB/Private/Code/go-projects/src/github.com/bIgBV/cereberus/app/node_modules/react/lib/React doesn't exist /Users/bIgB/Private/Code/go-projects/src/github.com/bIgBV/cereberus/app/node_modules/react/lib/Reactjs doesn't exist /Users/bIgB/Private/Code/go-projects/src/github.com/bIgBV/cereberus/app/node_modules/react/lib/Reactjsx doesn't exist
要解决此问题,只需.
在扩展程序的前面添加一个,如下所示:
resolve: { extensions: ['', '.js', '.jsx'] }
https://webpack.github.io/docs/configuration.html#resolve-extensions