Code language not supported or defined. in VS code

223 Views Asked by At

I am trying to run a code, this code is hosted in vite server for react framework and for javascript language. it was working fine while ago, but i don't know what happened suddenly, now after i run the code it shows Code language not supported or defined. the code here is a basic one, to just print "Hi there" using react (https://i.stack.imgur.com/fWDBF.png) (I am so sorry i cannot directly upload the image as i dont have 10 reputations!) The error it shows is

failed to load config from C:\Users\HP\Desktop\Todo app\The-todo-app\vite.config.js
 error when starting dev server:
TypeError: Cannot redefine property: File
    at Function.defineProperty (<anonymous>)
    at Object.<anonymous> (C:\Users\HP\Desktop\Todo app\The-todo-app\node_modules\@babel\core\lib\index.js:7:8)
    at Module._compile (node:internal/modules/cjs/loader:1241:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1295:10)
    at Module.load (node:internal/modules/cjs/loader:1091:32)
    at Module._load (node:internal/modules/cjs/loader:938:12)
    at Module.require (node:internal/modules/cjs/loader:1115:19)
    at require (node:internal/modules/helpers:130:18)
    at Object.<anonymous> (C:\Users\HP\Desktop\Todo app\The-todo-app\node_modules\@babel\core\lib\config\helpers\config-api.js:16:14)        
    at Module._compile (node:internal/modules/cjs/loader:1241:14)

My config file looks something like this

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

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

what should i do?

I tried running the .jsx file on the cmd itself still didn't work i just want it to run on the server after i press the run button!

1

There are 1 best solutions below

1
ankitaeth On

The error message "Code language not supported or defined" suggests that the code you are trying to run is not written in a language that is supported by the environment in which you are trying to run it.

    import React from 'react';
    
    const App = () => {
      return <div>Hi there!</div>;
    };
    
    export default App;

Create a new file called server.js and add the following code:

 const express = require('express');
    const React = require('react');
    const ReactDOMServer = require('react-dom/server');
    
    const app = express();
    
    app.get('/', (req, res) => {
      const App = require('./app.jsx').default;
      const html = ReactDOMServer.renderToString(<App />);
    
      res.send(html);
    });
    
    app.listen(3000, () => {
      console.log('Server listening on port 3000');
    });