生产中的Webpack:为什么React Native错误?

时间:2016-11-07 16:30:39

标签: javascript reactjs react-native webpack

我有一个安装了以下内容的测试应用程序:

"dependencies": {
  "express": "^4.14.0",
  "react": "^15.3.2",
  "react-dom": "^15.3.2"
},
"devDependencies": {
  "babel": "^6.5.2",
  "babel-core": "^6.18.2",
  "babel-loader": "^6.2.7",
  "babel-preset-es2015": "^6.18.0",
  "babel-preset-react": "^6.16.0",
  "webpack": "^1.13.3"
}

我的 webpack.config.js

module.exports = {
  entry: {
    'bundle': './client/index.js'
  },
  output: {
    path: './public',
    filename: 'js/[name].js'
  },
  plugins: [
    new webpack.ProvidePlugin({
      'process.env': {
        NODE_ENV: JSON.stringify('production')
      }
    })
  ],
  module: {
    loaders: [
      {
        test: /\.js$/,
        exclude: /(node_modules|bower_components)/,
        loader: 'babel-loader',
        query: { presets: ['es2015', 'react'] }
      }
    ]
  }
}

为什么我会收到这些 React Native 相关的错误.. ??我不是想使用React Native!

(当我删除webpack.ProvidePlugin()时,错误就会消失,但我需要React的生成版本。

   ./~/react/lib/NativeMethodsMixin.js中的错误   找不到模块:错误:无法在C:\ node \ sandbox \ react-webpack \ node_modules \ react \ lib中解析模块'react-native / lib / TextInputState'    @ ./~/react/lib/NativeMethodsMixin.js 17:21-63

      ./~/react/lib/NativeMethodsMixin.js中的错误   找不到模块:错误:无法在C:\ node \ sandbox \ react-webpack \ node_modules \ react \ lib中解析模块'react-native / lib / UIManager'    @ ./~/react/lib/NativeMethodsMixin.js 18:16-53

      ./~/react/lib/ReactNativeBaseComponent.js中的错误   找不到模块:错误:无法在C:\ node \ sandbox \ react-webpack \ node_modules \ react \ lib中解析模块'react-native / lib / UIManager'    @ ./~/react/lib/ReactNativeBaseComponent.js 22:16-53

      ./~/react/lib/ReactNativeBaseComponent.js中的错误   找不到模块:错误:无法在C:\ node \ sandbox \ react-webpack \ node_modules \ react \ lib中解析模块'react-native / lib / deepFreezeAndThrowOnMutationInDev'    @ ./~/react/lib/ReactNativeBaseComponent.js 24:40-101

      ./~/react/lib/ReactNativeAttributePayload.js中的错误   找不到模块:错误:无法在C:\ node \ sandbox \ react-webpack \ node_modules \ react \ lib中解析模块'react-native / lib / deepDiffer'    @ ./~/react/lib/ReactNativeAttributePayload.js 16:17-55

      ./~/react/lib/ReactNativeAttributePayload.js中的错误   找不到模块:错误:无法在C:\ node \ sandbox \ react-webpack \ node_modules \ react \ lib中解析模块'react-native / lib / flattenStyle'    @ ./~/react/lib/ReactNativeAttributePayload.js 17:19-59

      ./~/react/lib/ReactNativeBridgeEventPlugin.js中的错误   找不到模块:错误:无法在C:\ node \ sandbox \ react-webpack \ node_modules \ react \ lib中解析模块'react-native / lib / UIManager'    @ ./~/react/lib/ReactNativeBridgeEventPlugin.js 20:16-53

      ./~/react/lib/ReactNativeDOMIDOperations.js中的错误   找不到模块:错误:无法在C:\ node \ sandbox \ react-webpack \ node_modules \ react \ lib中解析模块'react-native / lib / UIManager'    @ ./~/react/lib/ReactNativeDOMIDOperations.js 15:16-53

     错误在./~/react/lib/ReactNativeDefaultInjection.js中   找不到模块:错误:无法在C:\ node \ sandbox \ react-webpack \ node_modules \ react \ lib中解析模块'react-native / lib / InitializeJavaScriptAppEngine'    @ ./~/react/lib/ReactNativeDefaultInjection.js 23:0-57

     错误在./~/react/lib/ReactNativeDefaultInjection.js中   找不到模块:错误:无法在C:\ node \ sandbox \ react-webpack \ node_modules \ react \ lib中解析模块'react-native / lib / RCTEventEmitter'    @ ./~/react/lib/ReactNativeDefaultInjection.js 27:22-65

     错误在./~/react/lib/ReactNativeDefaultInjection.js中   找不到模块:错误:无法在C:\ node \ sandbox \ react-webpack \ node_modules \ react \ lib中解析模块'react-native / lib / View'    @ ./~/react/lib/ReactNativeDefaultInjection.js 79:15-47

      /re/react/lib/ReactNativeGlobalResponderHandler.js中的错误   找不到模块:错误:无法在C:\ node \ sandbox \ react-webpack \ node_modules \ react \ lib中解析模块'react-native / lib / UIManager'    @ ./~/react/lib/ReactNativeGlobalResponderHandler.js 13:16-53

     错误在./~/react/lib/ReactNativeMount.js中   找不到模块:错误:无法在C:\ node \ sandbox \ react-webpack \ node_modules \ react \ lib中解析模块'react-native / lib / UIManager'    @ ./~/react/lib/ReactNativeMount.js 21:16-53

      ./~/react/lib/ReactNativeTextComponent.js中的错误   找不到模块:错误:无法在C:\ node \ sandbox \ react-webpack \ node_modules \ react \ lib中解析模块'react-native / lib / UIManager'    @ ./~/react/lib/ReactNativeTextComponent.js 19:16-53

      ./~/react/lib/ReactDOMFiber.js中的错误   找不到模块:错误:无法解析C:\ node \ sandbox \ react-webpack \ node_modules \ react \ lib中的'file'或'directory'./ReactFiberReconciler    @ ./~/react/lib/ReactDOMFiber.js 15:27-60

     错误在./~/react/lib/ReactNoop.js中   找不到模块:错误:无法解析C:\ node \ sandbox \ react-webpack \ node_modules \ react \ lib中的'file'或'directory'./ReactFiberReconciler    @ ./~/react/lib/ReactNoop.js 22:27-60

1 个答案:

答案 0 :(得分:2)

使用DefinePlugin而不是ProvidePlugin。这是用于此用例的插件。

我不明白触发这些错误的原因。我认为react确实包含一些特定于react-native的代码。