How to import npm packege – Nodejs

Any idea why I am getting an error?

  import Server from '';
  const socketio = new Server();


import Server from '';
SyntaxError: The requested module '' does not provide an export named 'default'


There are two kinds of exports: named exports (several per module) and default exports (one per module). It is possible to use both at the same time, but usually best to keep them separate.

Why are you receiving this error: The import statement you wrote, provides the Server which is not a default export. If had actually exported Server as below, then you would not get an error.

module.exports = {
  //Other exports
  Server as default

You could have done this:

import * as io from ""
import express from 'express';
import { createServer } from 'http';

const app = express(); 
const server = createServer(app); 
const socketio = new io.Server(server);

Leave a Reply

Your email address will not be published. Required fields are marked *