sam3d / next-plugin-websocket

Add WebSocket support to Next.js API routes
https://www.npmjs.com/package/next-plugin-websocket
56 stars 8 forks source link

aftre install package next utils.js error #9

Open theeranan opened 1 year ago

theeranan commented 1 year ago

yarn run v1.22.19 $ next D:\Dev\nextjs_ws_apollo\node_modules\next\dist\build\utils.js:1 "httpServer: server, ^^^^^^^^^^^^^^^^^^^^

SyntaxError: Invalid or unexpected token at internalCompileFunction (node:internal/vm:73:18) at wrapSafe (node:internal/modules/cjs/loader:1176:20) at Module._compile (node:internal/modules/cjs/loader:1218:27) at Module._extensions..js (node:internal/modules/cjs/loader:1308:10) at Module.load (node:internal/modules/cjs/loader:1117:32) at Module._load (node:internal/modules/cjs/loader:958:12) at Module.require (node:internal/modules/cjs/loader:1141:19) at require (node:internal/modules/cjs/helpers:110:18) at Object. (D:\Dev\nextjs_ws_apollo\node_modules\next\dist\build\worker.js:13:14) at Module._compile (node:internal/modules/cjs/loader:1254:14)

Node.js v18.16.0 error Command failed with exit code 1. info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

enex commented 1 year ago

The problem ist the patch expects new NextServer({ https://github.com/sam3d/next-plugin-websocket/blob/8d9e3e5fd99c6b11daf2b476f926a8b9af3faba4/src/patch.ts#L72 but can't find it and thus it inserts it at the top, because find index returns `-1`. A possible solution would be to find out where new NextServer({ is located now and target this file instead, also helpful would be an error if the line was not found.

Just my thoughts (next.js version 13.4.2)

tarik02 commented 1 year ago

The problem ist the patch expects new NextServer({

https://github.com/sam3d/next-plugin-websocket/blob/8d9e3e5fd99c6b11daf2b476f926a8b9af3faba4/src/patch.ts#L72 but can't find it and thus it inserts it at the top, because find index returns -1. A possible solution would be to find out where new NextServer({ is located now and target this file instead, also helpful would be an error if the line was not found.

Just my thoughts (next.js version 13.4.2)

Actually, for for next 13.4.10 it works without this patch (but requires patch from #6). It seems they just added httpServer there. Currently I just use this yarn patch:

.yarn/patches/next-plugin-websocket-npm-0.1.2-0ca3921bb0.patch

``` diff --git a/dist/index.js b/dist/index.js index 5f6fb7271d28b806eb4d47ec04f19a9a628df7f8..4501b2ed3005c552cecdae6d0737f6148b2ea953 100644 --- a/dist/index.js +++ b/dist/index.js @@ -78,7 +78,10 @@ function hookNextNodeServer() { if (!isPageFound) return false; // Ensure that the page gets built, if it exists - await this.ensureApiPage(page); + await this.ensureEdgeFunction({ + page, + appPaths: null, + }); // Get the path of the built page. Will throw an error if the page doesn't // exist. This is fine to ignore, as it just falls into one of the many // other 404's that Next.js doesn't really do anything with diff --git a/dist/patch.js b/dist/patch.js index 5c92ad9de13d1b15a61b1a08d36ddae98c22ad53..955e1f1d65ab8dd015855f41e53c6d7be13cb697 100644 --- a/dist/patch.js +++ b/dist/patch.js @@ -34,7 +34,7 @@ const mod = template_1.default.expression.ast `require("next-plugin-websocket")` async function main() { await patchNextNodeServer(); await patchWebpackConfig(); - await patchStandaloneServer(); + // await patchStandaloneServer(); } main(); async function patchNextNodeServer() { ```

tarik02 commented 1 year ago

Actually there is problem with standalone server (this https://github.com/vercel/next.js/issues/44209)

anurag-roy commented 6 months ago

Was anyone able to make this (or any other workaround) work for Next.js 14?