wobsoriano / nuxt3-socket.io

Nuxt 3 and Socket.io integration.
59 stars 9 forks source link

ESMLoader error #1

Closed s0loparty closed 1 year ago

s0loparty commented 1 year ago

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', ], })

lhoucinecherif commented 1 year ago

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)
FrodoTrash commented 1 year ago

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

timstrasser commented 1 year ago

Same for me. Is there any fix for that?

Renegade1912 commented 1 year ago

i could skip it with this edit:

https://github.com/wobsoriano/nuxt3-socket.io/blob/5cbf69c959594d8330f54bcc5250dadbd7f80388/src/module.ts#L59

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

after this i run into #5

Renegade1912 commented 1 year ago

https://github.com/wobsoriano/nuxt3-socket.io/blob/5cbf69c959594d8330f54bcc5250dadbd7f80388/src/module.ts#L1

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";

https://github.com/wobsoriano/nuxt3-socket.io/blob/5cbf69c959594d8330f54bcc5250dadbd7f80388/src/module.ts#L26

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

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

https://github.com/wobsoriano/nuxt3-socket.io/blob/5cbf69c959594d8330f54bcc5250dadbd7f80388/src/module.ts#L59

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

wobsoriano commented 1 year ago

Fixed in https://github.com/wobsoriano/nuxt3-socket.io/pull/7