Search code examples
reactjswebpackwebpack-4react-i18next

React Webpack: TypeError: react__WEBPACK_IMPORTED_MODULE_7___default.a.createContext


Recently I added i18next library to my React app. Compilation is successfull but I get this TypeError in console.

Uncaught TypeError: react__WEBPACK_IMPORTED_MODULE_7___default.a.createContext is not a function
    at eval (context.js:69)
    at Module../node_modules/react-i18next/dist/es/context.js (bundle.js:15948)
    at __webpack_require__ (bundle.js:20)
    at eval (withNamespaces.js:23)
    at Module../node_modules/react-i18next/dist/es/withNamespaces.js (bundle.js:15984)
    at __webpack_require__ (bundle.js:20)
    at eval (index.js:5)
    at Module../node_modules/react-i18next/dist/es/index.js (bundle.js:15960)
    at __webpack_require__ (bundle.js:20)
    at eval (i18n.js:11)

i18n is an example from https://react.i18next.com/guides/quick-start. I've tested it before using create-react-app (React 16.7) and it works well. In my app I'm using React 15.6 and Redux but it looks like Webpack issue.

index.js

/*@ NODE MODULES  */
import React from 'react';
import { render } from 'react-dom';
import { Provider } from 'react-redux';

/*@ LOCAL */
import i18n from './i18n';
import App from './components/App';
import configureStore from './store/configureStore';

const store = configureStore();

render(
    <Provider store={store}>
        <App />
    </Provider>,
    document.getElementById('mainApp')
);

package.json

...
"devDependencies": {
    "babel-core": "^6.26.0",
    "babel-loader": "^7.1.2",
    "babel-plugin-lodash": "^3.3.2",
    "babel-plugin-syntax-object-rest-spread": "^6.13.0",
    "babel-plugin-transform-class-properties": "^6.24.1",
    "babel-plugin-transform-decorators-legacy": "^1.3.4",
    "babel-polyfill": "^6.26.0",
    "babel-preset-env": "^1.6.1",
    "babel-preset-react": "^6.24.1",
    "babel-preset-stage-0": "^6.24.1",
    "chalk": "^2.3.0",
    "cross-env": "^5.1.1",
    "css-loader": "^0.23.1",
    "progress-bar-webpack-plugin": "^1.11.0",
    "style-loader": "^0.13.1",
    "webpack": "^4.16.1",
    "webpack-bundle-analyzer": "^3.0.2",
    "webpack-cli": "^3.0.8"
  },
...

Solution

  • I found solution. Different React version needs specific react-i18next version

     "react": "^15.6.2",
     "react-i18next": "^8.4.0",
    
    
    "react": "^16.3.2",
    "react-i18next": "^9.0.0",