Cannot access '__WEBPACK_DEFAULT_EXPORT__' before initialization
See original GitHub issueBug report
What is the current behavior? Throw error: Cannot access ‘WEBPACK_DEFAULT_EXPORT’ before initialization
If the current behavior is a bug, please provide the steps to reproduce. How to reproduce: Need too setup react project, without using Create React App, all is working fine, till I will not add i18next.js to my project, from i18next documentation, I need to create and export i18n function from file i18n.js and import this function in my root js file => index.js, but when I put this import I have error: Cannot access ‘WEBPACK_DEFAULT_EXPORT’ before initialization
webpack.config.json:
const HtmlWebpackPlugin = require("html-webpack-plugin")
const path = require("path")
module.exports = {
mode: "development",
entry: "./src/index.js",
output: {
filename: "bundle.[hash].js",
path: path.resolve(__dirname, "dist"),
},
plugins: [
new HtmlWebpackPlugin({
template: "./src/index.html",
}),
],
resolve: {
modules: [__dirname, "src", "node_modules"],
extensions: ["*", ".js", ".jsx", ".tsx", ".ts"],
},
performance: {
hints: false,
maxEntrypointSize: 512000,
maxAssetSize: 512000
},
devServer: {
historyApiFallback: true,
},
module: {
rules: [
{
test: /\.jsx?$/,
exclude: /node_modules/,
loader: require.resolve("babel-loader"),
},
{
test: /\.tsx?$/,
exclude: /node_modules/,
loader: require.resolve("babel-loader"),
},
{
test: /\.css$/,
use: ["style-loader", "css-loader"],
},
{
test: /\.png|svg|jpg|gif$/,
use: ["file-loader"],
}
],
},
}
i18next.js, where I nned to export my function:
import i18n from "i18next"
import { initReactI18next } from "react-i18next"
import Backend from "i18next-http-backend"
import LanguageDetector from "i18next-browser-languagedetector"
i18n.use(Backend).use(LanguageDetector).use(initReactI18next).init({
fallbackLng: "en",
debug: true,
interpolation: {
escapeValue: false,
}
})
export default i18n
index.js => where I need to import function
import React from "react"
import ReactDOM from "react-dom"
import App from "./app"
import "./i18next"
ReactDOM.render(<App />, document.querySelector("#root"))
Versions:
"webpack": "^5.37.0",
"webpack-cli": "^4.7.0",
"webpack-dev-server": "^3.11.2"
Error:
Uncaught ReferenceError: Cannot access '__WEBPACK_DEFAULT_EXPORT__' before initialization
at Module.default (i18next.js:3)
at eval (i18next.js:13)
at Module../src/i18next.js (bundle.60182540719e141031ac.js:173)
at __webpack_require__ (bundle.60182540719e141031ac.js:992)
at fn (bundle.60182540719e141031ac.js:1233)
at eval (index.js:2)
at Module../src/index.js (bundle.60182540719e141031ac.js:184)
at __webpack_require__ (bundle.60182540719e141031ac.js:992)
at bundle.60182540719e141031ac.js:2079
at bundle.60182540719e141031ac.js:2083
What is the expected behavior?
Expected not to have this error, because same code is working correctly if I will setup my project with Create React App, and component imports are also working correctly. In index.js I need to have access to i18n function from i18next.js
Issue Analytics
- State:
- Created 2 years ago
- Comments:12 (6 by maintainers)
Top GitHub Comments
i have tried to solve the issue by removing
"webpack": "^5.64.4",
version of webpack and then re- installing this versionwebpack@5.72.0
but i am still getting the same issue. here is my webpack config filePlease create reproducible test repo, it will be faster and easy to help, I think you have two version of webpack, and use webpack v4 instead webpack v5, run
npm ls webpack