Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncaught ReferenceError: Cannot Access 'X' Before Initialization in Production Build #3322

Open
zaid0088 opened this issue Mar 27, 2025 · 0 comments

Comments

@zaid0088
Copy link

zaid0088 commented Mar 27, 2025

Current behavior:

I am using @emotion/styled in a React + Vite project. The application works fine in development, but after deploying or doing yarn build and then yarn preview, there is an error coming from emotion

To reproduce:

Set up a React project with Vite.

Install @emotion/styled and @mui/material.

Use yarn build to build the app and yarn preview to run it

Open the app in a browser and observe the error.

Image

Expected behavior:

The app should work in production just as it does in development.

Environment information:

{
  "dependencies": {
    "@emotion/react": "^11.13.3",
    "@emotion/styled": "^11.13.0",
    "@mui/icons-material": "^6.1.6",
    "@mui/material": "^6.1.6",
    "axios": "^1.7.7",
    "framer-motion": "^11.11.11",
    "react": "^18.3.1",
    "react-dom": "^18.3.1",
    "react-router-dom": "^6.27.0",
    "styled-components": "^6.1.13",
    "vite-tsconfig-paths": "^5.1.0",
    "zustand": "^5.0.0"
  }
}

{
    "@eslint/js": "^9.21.0",
    "@types/react": "^19.0.10",
    "@types/react-dom": "^19.0.4",
    "@typescript-eslint/eslint-plugin": "^8.26.1",
    "@typescript-eslint/parser": "^8.26.1",
    "@vitejs/plugin-react": "^4.3.4",
    "eslint": "^9.22.0",
    "eslint-config-prettier": "^10.1.1",
    "eslint-plugin-prettier": "^5.2.3",
    "eslint-plugin-react": "^7.37.4",
    "eslint-plugin-react-hooks": "^5.1.0",
    "eslint-plugin-react-refresh": "^0.4.19",
    "globals": "^15.15.0",
    "husky": "^9.1.7",
    "lint-staged": "^15.5.0",
    "prettier": "^3.5.3",
    "typescript": "~5.7.2",
    "typescript-eslint": "^8.24.1",
    "vite": "5.4.9"
  }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant