ncc 0.21.1 Socket.io is not supported

Created on 26 Feb 2020  路  7Comments  路  Source: vercel/ncc

I am compiling nestjs project with NCC锛孉fter compiling, I found that it couldn't run.

error info:
[PackageLoader] No driver (WebSockets) has been selected. In order to take advantage of the default driver, please, ensure to install the "@nestjs/platform-socket.io" package ($ npm install @nestjs/platform-socket.io). +37ms

I used another koa based project and found that NCC does not support socket.io either
error info:

Error: Cannot find module 'socket.io-client/dist/socket.io.js'
Require stack:
- D:\ptyt_193\web_dispatch\ncc_dist_gis_server\index.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:981:15)
    at Function.resolve (internal/modules/cjs/helpers.js:83:19)
    at t (D:\ptyt_193\web_dispatch\ncc_dist_gis_server\index.js:2:1114698)
    at Server.serveClient (D:\ptyt_193\web_dispatch\ncc_dist_gis_server\index.js:2:1114724)
    at new Server (D:\ptyt_193\web_dispatch\ncc_dist_gis_server\index.js:2:1113690)
    at Server (D:\ptyt_193\web_dispatch\ncc_dist_gis_server\index.js:2:1113526)
    at Object.8497 (D:\ptyt_193\web_dispatch\ncc_dist_gis_server\index.js:2:2369676)
    at __webpack_require__ (D:\ptyt_193\web_dispatch\ncc_dist_gis_server\index.js:2:154)
    at startup (D:\ptyt_193\web_dispatch\ncc_dist_gis_server\index.js:2:291)
    at module.exports.10 (D:\ptyt_193\web_dispatch\ncc_dist_gis_server\index.js:2:347)
    at Object.<anonymous> (D:\ptyt_193\web_dispatch\ncc_dist_gis_server\index.js:2:357)
    at Module._compile (internal/modules/cjs/loader.js:1157:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1177:10)
    at Module.load (internal/modules/cjs/loader.js:1001:32)
    at Function.Module._load (internal/modules/cjs/loader.js:900:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)
    at internal/main/run_main_module.js:18:47
(node:1964) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.

Most helpful comment

I think the issue is that the code from package platform-socket.io is not used anywhere in the node-application and thus the package will not be included in the ncc output.

To fix this, I explicitly set the IoAdapter from platform-socket.io in my bootstap function (i.e. in main.ts):

import { IoAdapter } from '@nestjs/platform-socket.io';

async function bootstrap() {
  const app = await NestFactory.create(...);
  app.useWebSocketAdapter(new IoAdapter(app));
  ..
}

All 7 comments

I'm having the same problem

I just created the "node_modules/dist/" folder and added that socket.io.js file. This solved my problem. This is one file that socket.io will send to the client that must be in that folder.

I just created the "node_modules/dist/" folder and added that socket.io.js file. This solved my problem. This is one file that socket.io will send to the client that must be in that folder.

I think I didn't quite understand how you did it ... did you insert it into node_modules directly?

I think the issue is that the code from package platform-socket.io is not used anywhere in the node-application and thus the package will not be included in the ncc output.

To fix this, I explicitly set the IoAdapter from platform-socket.io in my bootstap function (i.e. in main.ts):

import { IoAdapter } from '@nestjs/platform-socket.io';

async function bootstrap() {
  const app = await NestFactory.create(...);
  app.useWebSocketAdapter(new IoAdapter(app));
  ..
}

I think the issue is that the code from package platform-socket.io is not used anywhere in the node-application and thus the package will not be included in the ncc output.

To fix this, I explicitly set the IoAdapter from platform-socket.io in my bootstap function (i.e. in main.ts):

import { IoAdapter } from '@nestjs/platform-socket.io';

async function bootstrap() {
  const app = await NestFactory.create(...);
  app.useWebSocketAdapter(new IoAdapter(app));
  ..
}

Your answer can solve the packing problem very well, thank you very much! But I think NCC officials should provide patches to solve this problem

I think the issue is that the code from package platform-socket.io is not used anywhere in the node-application and thus the package will not be included in the ncc output.
To fix this, I explicitly set the IoAdapter from platform-socket.io in my bootstap function (i.e. in main.ts):

import { IoAdapter } from '@nestjs/platform-socket.io';

async function bootstrap() {
  const app = await NestFactory.create(...);
  app.useWebSocketAdapter(new IoAdapter(app));
  ..
}

Your answer can solve the packing problem very well, thank you very much! But I think NCC officials should provide patches to solve this problem

I try this , it just fixed the first problem .

when i run it node index.js , I have the other error:

Error: Cannot find module 'socket.io-client/dist/socket.io.js'
....
....

it seems to depend on node_modules with package "socket.io-client"

so I tryed to install it ..

npm init
npm install socket.io-client --save 
node index.js 

successfully~

Was this page helpful?
0 / 5 - 0 ratings

Related issues

andykais picture andykais  路  4Comments

coetry picture coetry  路  5Comments

paulogdm picture paulogdm  路  5Comments

j picture j  路  3Comments

GiladShoham picture GiladShoham  路  3Comments