Issue to run ReactTS + Vite + SWC project

59 Views Asked by At

Issue is the run locally ReactTs project (Vite and SWC): Error message, npm run dev:

> [email protected] dev
> vite

✘ [ERROR] Unexpected end of file in JSON

    ../tsconfig.json:1:0:
      1 │ 
        ╵ ^

failed to load config from /home/n.n/Desktop/meeting-assistant/vite.config.ts
error when starting dev server:
Error: Build failed with 1 error:
../tsconfig.json:1:0: ERROR: Unexpected end of file in JSON
    at failureErrorWithLog (/home/n.n/Desktop/meeting-assistant/node_modules/esbuild/lib/main.js:1651:15)
    at /home/n.n/Desktop/meeting-assistant/node_modules/esbuild/lib/main.js:1059:25
    at runOnEndCallbacks (/home/n.n/Desktop/meeting-assistant/node_modules/esbuild/lib/main.js:1486:45)
    at buildResponseToResult (/home/n.n/Desktop/meeting-assistant/node_modules/esbuild/lib/main.js:1057:7)
    at /home/n.n/Desktop/meeting-assistant/node_modules/esbuild/lib/main.js:1086:16
    at responseCallbacks.<computed> (/home/n.n/Desktop/meeting-assistant/node_modules/esbuild/lib/main.js:704:9)
    at handleIncomingPacket (/home/n.n/Desktop/meeting-assistant/node_modules/esbuild/lib/main.js:764:9)
    at Socket.readFromStdout (/home/n.n/Desktop/meeting-assistant/node_modules/esbuild/lib/main.js:680:7)
    at Socket.emit (node:events:513:28)
    at addChunk (node:internal/streams/readable:324:12)

My machine is Linux Ubuntu 22.04.4 LTS, Node 18.12.1, NPM 8.19.2, TSC on machine is: 4.5.4 but in project is latest

Code is:

package.json:

{
  "name": "meeting-assistant",
  "private": true,
  "version": "1.0.0",
  "type": "module",
  "scripts": {
    "dev": "vite",
    "build": "tsc && vite build",
    "lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
    "preview": "vite preview"
  },
  "dependencies": {
    "react": "^18.2.0",
    "react-dom": "^18.2.0"
  },
  "devDependencies": {
    "@types/node": "^20.11.19",
    "@types/react": "^18.2.56",
    "@types/react-dom": "^18.2.19",
    "@typescript-eslint/eslint-plugin": "^7.0.2",
    "@typescript-eslint/parser": "^7.0.2",
    "@vitejs/plugin-react-swc": "^3.5.0",
    "eslint": "^8.56.0",
    "eslint-config-prettier": "^9.1.0",
    "eslint-import-resolver-alias": "^1.1.2",
    "eslint-plugin-import-helpers": "^1.3.1",
    "eslint-plugin-prettier": "^5.1.3",
    "eslint-plugin-react": "^7.33.2",
    "eslint-plugin-react-hooks": "^4.6.0",
    "typescript": "^5.2.2",
    "vite": "^5.1.4"
  }
}

tsconfig.json:

{
  "compilerOptions": {
    "baseUrl": "./src",
    "types": ["node", "vite/client"],
    "target": "ES2020",
    "useDefineForClassFields": true,
    "lib": ["ES2020", "DOM", "DOM.Iterable"],
    "module": "ESNext",
    "skipLibCheck": true,

    /* Bundler mode */
    "moduleResolution": "bundler",
    "allowImportingTsExtensions": true,
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "react-jsx",

    /* Linting */
    "strict": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "noFallthroughCasesInSwitch": true
  },
  "include": ["src"],
  "extends": "./tsconfig.paths.json",
  "references": [{ "path": "./tsconfig.node.json" }]
}

tsconfig.node.json:

{
  "compilerOptions": {
    "composite": true,
    "skipLibCheck": true,
    "module": "ESNext",
    "moduleResolution": "bundler",
    "allowSyntheticDefaultImports": true,
    "strict": true
  },
  "include": ["vite.config.ts"]
}

tsconfig.paths.json:

{
  "compilerOptions": {
    "paths": {
      "~/*": ["./*"]
    }
  }
}

vite.config.ts:

import react from '@vitejs/plugin-react-swc';
import { resolve } from 'node:path';
import { defineConfig } from 'vite';

// https://vitejs.dev/config/
export default defineConfig({
  base: '/',
  plugins: [react()],
  resolve: {
    alias: {
      '~': resolve(__dirname, './src')
    }
  },
  server: {
    port: 3000,
    watch: {
      ignored: ['**/coverage/**']
    }
  }
});

I already try to delete package-lock and node_modules, and clean install npm. I also already tried with npm i -g vite to install globally vite.

0

There are 0 best solutions below