2016-11-07 48 views
2

我與安裝下列測試程序:生產中的Webpack:爲什麼React Native錯誤?

"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!

(當我刪除webpack.ProvidePlugin()錯誤消失了,但我需要React的生成版本)。

ERROR in ./~/react/lib/NativeMethodsMixin.js Module not found: Error: Cannot resolve module 'react-native/lib/TextInputState' in C:\node\sandbox\react-webpack\node_modules\react\lib @ ./~/react/lib/NativeMethodsMixin.js 17:21-63

ERROR in ./~/react/lib/NativeMethodsMixin.js Module not found: Error: Cannot resolve module 'react-native/lib/UIManager' in C:\node\sandbox\react-webpack\node_modules\react\lib @ ./~/react/lib/NativeMethodsMixin.js 18:16-53

ERROR in ./~/react/lib/ReactNativeBaseComponent.js Module not found: Error: Cannot resolve module 'react-native/lib/UIManager' in C:\node\sandbox\react-webpack\node_modules\react\lib @ ./~/react/lib/ReactNativeBaseComponent.js 22:16-53

ERROR in ./~/react/lib/ReactNativeBaseComponent.js Module not found: Error: Cannot resolve module 'react-native/lib/deepFreezeAndThrowOnMutationInDev' in C:\node\sandbox\react-webpack\node_modules\react\lib @ ./~/react/lib/ReactNativeBaseComponent.js 24:40-101

ERROR in ./~/react/lib/ReactNativeAttributePayload.js Module not found: Error: Cannot resolve module 'react-native/lib/deepDiffer' in C:\node\sandbox\react-webpack\node_modules\react\lib @ ./~/react/lib/ReactNativeAttributePayload.js 16:17-55

ERROR in ./~/react/lib/ReactNativeAttributePayload.js Module not found: Error: Cannot resolve module 'react-native/lib/flattenStyle' in C:\node\sandbox\react-webpack\node_modules\react\lib @ ./~/react/lib/ReactNativeAttributePayload.js 17:19-59

ERROR in ./~/react/lib/ReactNativeBridgeEventPlugin.js Module not found: Error: Cannot resolve module 'react-native/lib/UIManager' in C:\node\sandbox\react-webpack\node_modules\react\lib @ ./~/react/lib/ReactNativeBridgeEventPlugin.js 20:16-53

ERROR in ./~/react/lib/ReactNativeDOMIDOperations.js Module not found: Error: Cannot resolve module 'react-native/lib/UIManager' in C:\node\sandbox\react-webpack\node_modules\react\lib @ ./~/react/lib/ReactNativeDOMIDOperations.js 15:16-53

ERROR in ./~/react/lib/ReactNativeDefaultInjection.js Module not found: Error: Cannot resolve module 'react-native/lib/InitializeJavaScriptAppEngine' in C:\node\sandbox\react-webpack\node_modules\react\lib @ ./~/react/lib/ReactNativeDefaultInjection.js 23:0-57

ERROR in ./~/react/lib/ReactNativeDefaultInjection.js Module not found: Error: Cannot resolve module 'react-native/lib/RCTEventEmitter' in C:\node\sandbox\react-webpack\node_modules\react\lib @ ./~/react/lib/ReactNativeDefaultInjection.js 27:22-65

ERROR in ./~/react/lib/ReactNativeDefaultInjection.js Module not found: Error: Cannot resolve module 'react-native/lib/View' in C:\node\sandbox\react-webpack\node_modules\react\lib @ ./~/react/lib/ReactNativeDefaultInjection.js 79:15-47

ERROR in ./~/react/lib/ReactNativeGlobalResponderHandler.js Module not found: Error: Cannot resolve module 'react-native/lib/UIManager' in C:\node\sandbox\react-webpack\node_modules\react\lib @ ./~/react/lib/ReactNativeGlobalResponderHandler.js 13:16-53

ERROR in ./~/react/lib/ReactNativeMount.js Module not found: Error: Cannot resolve module 'react-native/lib/UIManager' in C:\node\sandbox\react-webpack\node_modules\react\lib @ ./~/react/lib/ReactNativeMount.js 21:16-53

ERROR in ./~/react/lib/ReactNativeTextComponent.js Module not found: Error: Cannot resolve module 'react-native/lib/UIManager' in C:\node\sandbox\react-webpack\node_modules\react\lib @ ./~/react/lib/ReactNativeTextComponent.js 19:16-53

ERROR in ./~/react/lib/ReactDOMFiber.js Module not found: Error: Cannot resolve 'file' or 'directory' ./ReactFiberReconciler in C:\node\sandbox\react-webpack\node_modules\react\lib @ ./~/react/lib/ReactDOMFiber.js 15:27-60

ERROR in ./~/react/lib/ReactNoop.js Module not found: Error: Cannot resolve 'file' or 'directory' ./ReactFiberReconciler in C:\node\sandbox\react-webpack\node_modules\react\lib @ ./~/react/lib/ReactNoop.js 22:27-60

+0

嘗試徹底刪除node_modules文件夾並再次從乾淨狀態安裝deps。如果您可以將您的測試應用推送到Github,我很樂意將其克隆並自行嘗試。 –

+0

這真是太好了:https://github.com/stephen-last/react-webpack-test –

+0

等等。你不應該使用'DefinePlugin'而不是'ProvidePlugin'嗎?我在我的項目中使用了'DefinePlugin'。 –

回答

2

使用DefinePlugin而不是ProvidePlugin。這是用於此用例的插件。

我不明白是什麼觸發了這些錯誤。我認爲react確實包含一些特定於react-native的代碼。

+0

輝煌 - 就是這樣......它現在可行......沒有人在之前發現過兩堆問題。謝謝! –

相關問題