Search code examples
visual-studio-codetsx

"Code language not supported or defined" when running a .tsx file in Visual Studio


I'm trying to follow a tutorial, it seems I just have this issue and not them despite doing everything the same. My visual studio is updated to the latest on my mac

Here is a screenshot https://pasteboard.co/UQdLgJ1AXGNB.png

I tried running coderunner to switch it from TypeScript.TSX to Javascript.TSX and it didn't help. No output change in my localhost:3000

UPDATE: I managed to kind of get things to work by switching the terminal to node and running "npm dev run" from there and launching. But cannot run without doing this each time.


Solution

  • This is not indeed an issue. The purpose of Run Code feature (aka Code Runner) is to execute code snippets or scripts within the editor. It's not intended to start a React application as you would with a development server.

    When we setup our application, we get a package.json which has some scripts defined inside it. These are intended to be used as npm run script_name (e.g. "npm run dev" or "npm run start").

    Conclusion: You do need to run it like npm run dev from the terminal.

    Hope this helps :)