nuxt / devtools

Unleash Nuxt Developer Experience
https://devtools.nuxt.com
MIT License
2.91k stars 161 forks source link

fix: VS Code Server docs chaos #737

Open zerescas opened 1 month ago

zerescas commented 1 month ago

🐛 The bug

There is a section in documentation about VS Code Server, but I can't get working it.

Part 1 - Follow the docs

Installing code-server from coder as proposes the docs leads to an error:

ℹ Nuxt DevTools: Starting VS Code Server at http://localhost:3080/?folder=%2Fapp ... ${{\color{red}{\textsf{ [2024-09-24T06:00:05.623Z] error Unknown option --accept-server-license-terms }}}}\$

and tab with VS Code freezes with Starting... image

Part 2 - Follow the VS Code tab

The tab VS Code has link that leads to the Microsoft website

Learn more about it with this guide.

image Installing vscode-server and reloading Nuxt leads to new error:

ℹ Nuxt DevTools: Starting VS Code Server at http://localhost:3080/?folder=%2Fapp ... ${{\color{red}{\textsf{ /usr/local/bin/code-server: 2: Syntax error: newline unexpected }}}}\$

Also launching code-server from CLI leads to errors:

root@3a11cfec517f:/app# code-server ${{\color{red}{\textsf{ /usr/local/bin/code-server: line 1: syntax error near unexpected token `newline' }}}}\$

${{\color{red}{\textsf{ /usr/local/bin/code-server: line 1: `<!DOCTYPE html>' }}}}\$

As I could found, this error tied with replacing code-server with VS Code CLI

🛠️ To reproduce

See "Additional context"

🌈 Expected behavior

Consistent and clear docs about VS Code Server because now next contradict each other:

And in the end nor of these ways working

ℹ️ Additional context

I tried this on:

To reproduce this, just use Nuxt example project

npx nuxi@latest init

and do steps from 🐛 The bug

hachimetsu commented 1 month ago

remove code-server and install it using `npm i -g code-server' then try it

hachimetsu commented 1 month ago

instead of creating new issue i am putting this here if someone using cloud IDE like Github Codespace or Gitpod and unable to use devtool or want to use code-server

IDK if it's correct method or may be not best

but work for me

// https://nuxt.com/docs/api/configuration/nuxt-config
import * as fs from 'node:fs'

export default defineNuxtConfig({
  compatibilityDate: '2024-04-03',
  devtools: { enabled: true},
  vite: {
    server: {
      https: {
        key: fs.readFileSync('localhost-key.pem'),
        cert: fs.readFileSync('localhost-cert.pem')
      },
      hmr: {
        protocol: 'wss',
      }
    },
  },
})
openssl req -new -x509 -key localhost-key.pem -out localhost-cert.pem -days 365 -subj "/CN=localhost"
openssl genrsa -out localhost-key.pem 2048
$ grep -r 'accept-server-license-terms' node_modules/
node_modules/@nuxt/devtools/dist/chunks/vscode.mjs:      "--accept-server-license-terms",
node_modules/@nuxt/devtools/dist/chunks/vscode.mjs:          "--accept-server-license-terms",
node_modules/@nuxt/devtools/dist/chunks/vscode.mjs:      "--accept-server-license-terms",

Comment out flags which are not working

and replace http://localhost:${port}/ with url generate by online ide like