wobsoriano/nuxt3-socket.io

ESMLoader error

Closed this issue · 6 comments

Hey. Look at some error
OS win10 x64

npm run dev

`Nuxi 3.0.0 03:44:56
Nuxt 3.0.0 with Nitro 1.0.0 03:44:56
03:44:57

Local: http://localhost:3000/
Network: http://192.168.1.50:3000/

i Using Tailwind CSS from ~/assets/css/tailwind.css nuxt:tailwindcss 03:44:58
i Tailwind Viewer: http://localhost:3000/_tailwind/ nuxt:tailwindcss 03:44:58

ERROR Cannot start nuxt: Only URLs with a scheme in: file, data are supported by the default ESM loader. On Windows, absolute paths must be valid file:// URLs. Received protocol 'd:'

at new NodeError (node:internal/errors:372:5)
at throwIfUnsupportedURLScheme (node:internal/modules/esm/resolve:1120:11)
at defaultResolve (node:internal/modules/esm/resolve:1200:3)
at ESMLoader.resolve (node:internal/modules/esm/loader:580:30)
at ESMLoader.getModuleJob (node:internal/modules/esm/loader:294:18)
at ESMLoader.import (node:internal/modules/esm/loader:380:22)
at importModuleDynamically (node:internal/modules/esm/translators:106:35)
at importModuleDynamicallyCallback (node:internal/process/esm_loader:35:14)
at /D:/apps/nuxt3-mysql-docker/node_modules/nuxt3-socket.io/dist/module.mjs:50:27
at /D:/apps/nuxt3-mysql-docker/node_modules/hookable/dist/index.mjs:39:82`

package:
{ "private": true, "scripts": { "build": "nuxt build", "dev": "nuxt dev", "generate": "nuxt generate", "preview": "nuxt preview", "postinstall": "nuxt prepare", "start": "node .output/server/index.mjs" }, "devDependencies": { "@nuxtjs/tailwindcss": "^6.2.0", "nuxt": "3.0.0", "prisma": "^4.8.0" }, "dependencies": { "@prisma/client": "^4.8.0", "nuxt3-socket.io": "^0.0.11", "puppeteer": "^19.4.1", "socket.io": "^4.5.4", "socket.io-client": "^4.5.4" } }

nuxt.config
// https://nuxt.com/docs/api/configuration/nuxt-config export default defineNuxtConfig({ modules: [ '@nuxtjs/tailwindcss', 'nuxt3-socket.io', ], })

I got the same error !!

 ERROR  Cannot restart nuxt:  Only file and data URLs are supported by the default ESM loader. On Windows, absolute paths must be valid file:// URLs. Received protocol 'd:'
  at new NodeError (node:internal/errors:371:5)
  at defaultResolve (node:internal/modules/esm/resolve:1016:11)
  at ESMLoader.resolve (node:internal/modules/esm/loader:422:30)
  at ESMLoader.getModuleJob (node:internal/modules/esm/loader:222:40)
  at ESMLoader.import (node:internal/modules/esm/loader:276:22)
  at importModuleDynamically (node:internal/modules/esm/translators:111:35)
  at importModuleDynamicallyCallback (node:internal/process/esm_loader:35:14)
  at /D:/Web/Apps/checkbook-v2/web/node_modules/.pnpm/nuxt3-socket.io@0.0.11/node_modules/nuxt3-socket.io/dist/module.mjs:50:27
  at /D:/Web/Apps/checkbook-v2/web/node_modules/.pnpm/hookable@5.4.2/node_modules/hookable/dist/index.mjs:39:82
  at async load (/D:/Work/Apps/checkbook-v2/web/node_modules/.pnpm/nuxi@3.0.0/node_modules/nuxi/dist/chunks/dev.mjs:6780:9)
  at async _applyPromised (/D:/Web/Apps/checkbook-v2/web/node_modules/.pnpm/nuxi@3.0.0/node_modules/nuxi/dist/chunks/dev.mjs:6713:10)

same error here, happens when putting 'nuxt3-socket.io', in modules in nuxt.config.ts

Same for me. Is there any fix for that?

i could skip it with this edit:

const devFunctionsPath = resolve(nuxt.options.buildDir, 'io-dev-functions.mjs')

const devFunctionsPath = pathToFileURL(resolve(nuxt.options.buildDir, "io-dev-functions.mjs")).toString();

after this i run into #5

import { fileURLToPath } from 'url'

import { fileURLToPath, pathToFileURL } from "url";
import {
  defineNuxtModule,
  addServerHandler,
  addTemplate,
  createResolver
} from "@nuxt/kit";
import fg from "fast-glob";
import { Server as SocketServer, ServerOptions } from "socket.io";

const extGlob = '**/*.{ts,js,mjs}'

  async setup(options, nuxt) {
    const { resolve } = createResolver(import.meta.url);

    const extGlob = "**/*.{ts,js,mjs}";
    const files: string[] = [];

const devFunctionsPath = resolve(nuxt.options.buildDir, 'io-dev-functions.mjs')

const devFunctionsPath = pathToFileURL(
        resolve(nuxt.options.buildDir, "io-dev-functions.mjs")
      ).toString();

These changes did work for me. I just added it as a own module into my nuxt3 app.

image

Fixed in #7