harlan-zw / nuxt-seo

The complete SEO solution for Nuxt.
https://nuxtseo.com
MIT License
1.08k stars 70 forks source link

WebSocketServer not found #26

Closed blumgart closed 1 year ago

blumgart commented 1 year ago

Describe the bug

The project does not start after adding this module.

SEO Kit v1.2.2 • All-in-one SEO by @harlan_zw                                                                                                                                                               15:26:04  
  └─ 💖 Like this package? Consider sponsoring me on GitHub https://github.com/sponsors/harlan-zw                                                                                                           15:26:04  
                                                                                                                                                                                                            15:26:04  

 ERROR  Cannot restart nuxt:  Named export 'WebSocketServer' not found. The requested module 'ws' is a CommonJS module, which may not support all module.exports as named exports.                          15:26:04  
CommonJS modules can always be imported via the default export, for example using:

import pkg from 'ws';
const {WebSocketServer}from"ws";const tinyws=(wsOptions,wss=new WebSocketServer({...wsOptions,noServer:!0}))=>async(req,_,next)=>{0===(req.headers.upgrade||"").split(",").map((s=>s.trim())).indexOf("websocket")&&(r
eq.ws=()=>new Promise((resolve=>{wss.handleUpgrade(req,req.socket,Buffer.alloc(0),(ws=>{wss.emit("connection",ws,req),resolve(ws)}))}))),await next()};export{tinyws} = pkg;

  import{WebSocketServer}from"ws";const tinyws=(wsOptions,wss=new WebSocketServer({...wsOptions,noServer:!0}))=>async(req,_,next)=>{0===(req.headers.upgrade||"").split(",").map((s=>s.trim())).indexOf("websocket")&&
(req.ws=()=>new Promise((resolve=>{wss.handleUpgrade(req,req.socket,Buffer.alloc(0),(ws=>{wss.emit("connection",ws,req),resolve(ws)}))}))),await next()};export{tinyws};
  ^^^^^^^^^^^^^^^
  SyntaxError: Named export 'WebSocketServer' not found. The requested module 'ws' is a CommonJS module, which may not support all module.exports as named exports.
  CommonJS modules can always be imported via the default export, for example using:

  import pkg from 'ws';
  const {WebSocketServer}from"ws";const tinyws=(wsOptions,wss=new WebSocketServer({...wsOptions,noServer:!0}))=>async(req,_,next)=>{0===(req.headers.upgrade||"").split(",").map((s=>s.trim())).indexOf("websocket")&&
(req.ws=()=>new Promise((resolve=>{wss.handleUpgrade(req,req.socket,Buffer.alloc(0),(ws=>{wss.emit("connection",ws,req),resolve(ws)}))}))),await next()};export{tinyws} = pkg;

Reproduction

No response

System Info

System:
    OS: Windows 10 10.0.22621
    CPU: (12) x64 AMD Ryzen 5 5600H with Radeon Graphics
    Memory: 1.77 GB / 15.36 GB
  Binaries:
    Node: 18.4.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.17 - ~\AppData\Roaming\npm\yarn.CMD
    npm: 8.12.1 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Spartan (44.22621.1105.0), Chromium (109.0.1518.70)
    Internet Explorer: 11.0.22621.1

Used Package Manager

yarn

Validations

harlan-zw commented 1 year ago

Hey @blumgart, thanks for the issue.

This is very strange. Could you confirm your nuxi info and maybe package.json,

Seems like you might have a dependency also using ws for an older version. You can also test this with yarn why ws

blumgart commented 1 year ago

Yes, of course.

npx nuxi

------------------------------
- Operating System: `Windows_NT`
- Node Version:     `v18.4.0`
- Nuxt Version:     `3.1.2`
- Nitro Version:    `2.1.2`
- Package Manager:  `yarn@1.22.17`
- Builder:          `vite`
- User Config:      `app`, `modules`, `tailwindcss`, `image`, `critters`, `build`, `googleFonts`, `experimental`, `runtimeConfig`, `routeRules`
- Runtime Modules:  `@nuxtjs/tailwindcss@6.3.1`, `@nuxt/image-edge@1.0.0-27919678.2f5b64b`, `@nuxtjs/critters@0.4.0`, `@nuxtjs/google-fonts@3.0.0-1`, `@vueuse/nuxt@9.12.0`, `nuxt-icon@0.1.8`, `nuxt-lodash@2.4.1`, `@pinia/nuxt@0.4.6`
- Build Modules:    `-`
------------------------------

package.json

{
  "private": true,
  "scripts": {
    "build": "nuxt build",
    "dev": "nuxt dev",
    "generate": "nuxt generate",
    "preview": "nuxt preview",
    "postinstall": "nuxt prepare",
    "lhci:mobile": "lhci autorun",
    "lhci:desktop": "lhci autorun --collect.settings.preset=desktop"
  },
  "devDependencies": {
    "@headlessui/vue": "^1.7.4",
    "@lhci/cli": "^0.10.0",
    "@nuxt/image-edge": "^1.0.0-27719579.87dcdf2",
    "@nuxtjs/google-fonts": "^3.0.0-1",
    "@nuxtjs/html-validator": "^1.1.0",
    "@nuxtjs/tailwindcss": "^6.0.0",
    "@tailwindcss/forms": "^0.5.3",
    "@tailwindcss/line-clamp": "^0.4.2",
    "@tailwindcss/typography": "^0.5.8",
    "@vueuse/core": "^9.5.0",
    "@vueuse/nuxt": "^9.5.0",
    "nuxt": "^3.1.2",
    "nuxt-icon": "^0.1.6",
    "nuxt-lodash": "^2.4.1",
    "nuxt-seo-kit": "^1.2.2",
    "tailwind-scrollbar": "^2.1.0-preview.0",
    "vite-plugin-vue-inspector": "^3.3.0"
  },
  "dependencies": {
    "@chenfengyuan/vue-countdown": "2",
    "@headlessui/tailwindcss": "^0.1.2",
    "@nuxtjs/critters": "^0.4.0",
    "@pinia/nuxt": "^0.4.6",
    "@splidejs/splide": "^4.1.4",
    "@splidejs/vue-splide": "^0.6.12",
    "@vuelidate/core": "^2.0.0",
    "@vuelidate/validators": "^2.0.0",
    "collect.js": "^4.34.3",
    "maska": "^2.1.1",
    "nanoid": "^4.0.0",
    "nuxt-security": "^0.3.0",
    "postcss-custom-properties": "^13.1.0",
    "uuid": "^9.0.0",
    "vue-photo-zoom-pro": "^3.0.0"
  }
}

I found error - "@lhci/cli": "^0.10.0" i remove this package and works again. Thanks

harlan-zw commented 1 year ago

Great :)