2017-04-06 156 views
0

我有一个Rails应用程序,它在前端包含许多反应组件,最近尝试添加另一个事件时由于多个版本的反应而开始中断。webpack 1 build peerDependencies can not be found

回顾并更新旧代码,以便所有代码都可以在[email protected]我决定使用peerDependencies,以便每个功能都不会加载到它自己的反应库实例中。

在发展peerDependencies工作正常,但试图建立生产时,我得到的错误:

Cannot resolve module 'react' in /Users/path/to/project/lib/toaster @ ... 

我缺少什么?

的package.json:

{ 
    "name": "my-package", 
    // ... omitted ... 
    "scripts": { 
    "test": "NODE_ENV=development testem ci", 
    "testem": "testem -g", 
    "start": "webpack --watch", 
    "build": "webpack -p --config ./webpack.production.config.js --progress --profile --colors --preserve-symlinks" 
    }, 
    "repository": { // ... omitted ... }, 
    "devDependencies": { 
    "babel-core": "^6.4.5", 
    "babel-loader": "^6.2.1", 
    "babel-preset-es2015": "^6.3.13", 
    "babel-preset-react": "^6.23.0", 
    "browser-sync": "^2.17.2", 
    "browser-sync-webpack-plugin": "^1.1.3", 
    "bundle-collapser": "^1.1.1", 
    "del": "^1.1.1", 
    "envify": "^3.2.0", 
    "es6-promise": "^2.0.1", 
    "tape": "^4.0.0", 
    "testem": "^0.6.35", 
    "webpack": "^1.13.2" 
    }, 
    "peerDependencies": { 
    "react": "^15.3.2", 
    "react-dom": "^15.3.2" 
    }, 
    "dependencies": { 
    "empty": "^0.10.0", 
    "lodash": "^3.9.1", 
    "react-addons-css-transition-group": "^15.4.2" 
    } 
} 

webpack.production.config.js

var path = require('path'); 
var webpack = require('webpack'); 

module.exports = { 
    entry: [ 
    ... 
    ], 
    devtool: 'eval', 
    output: { 
    path: path.join(__dirname, "output"), 
    filename: 'index.js', 
    library: 'my-package', 
    libraryTarget: 'umd' 
    }, 
    resolveLoader: { 
    modules: ['..', 'node_modules'] 
    }, 
    plugins: [ 
    new webpack.DefinePlugin({ 
     // This has effect on the react lib size. 
     "process.env": { 
     NODE_ENV: JSON.stringify("production") 
     } 
    }), 
    new webpack.IgnorePlugin(/vertx/), 
    new webpack.IgnorePlugin(/configs/), 
    new webpack.IgnorePlugin(/un~$/), 
    new webpack.optimize.DedupePlugin(), 
    new webpack.optimize.UglifyJsPlugin(), 
    ], 
    resolve: { 
    extensions: ['.js', '.jsx'] 
    }, 
    module: { 
    loaders: [ 
     { 
     test: /.jsx?$/, 
     loader: 'babel-loader', 
     exclude: /node_modules/, 
     query: { 
      presets: ['es2015', 'react'] 
     } 
     } 
    ] 
    } 
}; 

回答

0

我想通了......

这不得不无关peerDependencies。这个问题在我webpack.production.config.js文件resolve

resolve: { 
    extensions: ['.js', '.jsx'] 
} 

需要下是

resolve: { 
    extensions: ['', '.js', '.jsx'] 
} 

,它是我的正常webpack.config.js文件

相关问题