mrcoder
mrcoder

Reputation: 360

React : Uncaught SyntaxError: Unexpected token 'export'

I am new to react just started few days ago, everything was working fine before and it still works fine in local. Only when I deploy the project on production react build file throws this error

Uncaught SyntaxError: Unexpected token 'export'

This this the piece of build file, it's last line. I am not sure why export is here.

("root")).render(p.jsx(v.StrictMode,{children:p.jsx(EI,{})}))});export default CI();

This is my vite.config.js

import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [react()],
})

This is Package.json

{
  "name": "myaccount-page",
  "private": true,
  "version": "0.0.0",
  "type": "module",
  "scripts": {
    "dev": "vite",
    "build": "vite build",
    "lint": "eslint . --ext js,jsx --report-unused-disable-directives --max-warnings 0",
    "preview": "vite preview"
  },
  "dependencies": {
    "axios": "^1.7.2",
    "bootstrap": "^4.6.2",
    "bootstrap-icons": "^1.11.3",
    "cropperjs": "^1.6.2",
    "react": "^18.3.1",
    "react-bootstrap": "^2.10.4",
    "react-color": "^2.19.3",
    "react-cropper": "^2.3.3",
    "react-dom": "^18.3.1",
    "react-easy-crop": "^5.0.8",
    "react-toastify": "^10.0.5"
  },
  "devDependencies": {
    "@types/react": "^18.3.3",
    "@types/react-dom": "^18.3.0",
    "@vitejs/plugin-react": "^4.3.1",
    "eslint": "^8.57.0",
    "eslint-plugin-react": "^7.34.3",
    "eslint-plugin-react-hooks": "^4.6.2",
    "eslint-plugin-react-refresh": "^0.4.7",
    "vite": "^5.3.4"
  }
}

I don't know what I am doing wrong, But this happened after using react-cropper and react-color packages. Please help, I am completely new member in react family.

UPDATE I don't know yet what was the issue but as i mentioned this happened after using react-color, so i removed react-color and all worked. Thank you to all who read and didn't say anything and who didn't understand and negative marked it. Thanks again.

Upvotes: -1

Views: 663

Answers (1)

Dylan
Dylan

Reputation: 64

Probaly because of the issue was related to the react-color package. let try re-install node_module:

rm -rf node_modules
rm package-lock.json
npm install

or try config defineConfig:

import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'

// https://vitejs.dev/config/
export default defineConfig({
 plugins: [react()],
 build: {
    target: 'esnext'
 }
})

Upvotes: 0

Related Questions