Next.js Discord

Discord Forum

socket.io and typescript

Answered
Sun bear posted this in #help-forum
Open in Discord
Avatar
Sun bearOP
i just want to start project with typescript but it not working
Image
Answered by ncls.
Mostly default:
{
  "compilerOptions": {
    "target": "es2016",
    "module": "commonjs",
    "outDir": "./dist",
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "strict": true,
    "skipLibCheck": true
  }
}
View full answer

24 Replies

Avatar
ncls.
What's the error?
Avatar
Sun bearOP
@ncls.
Image
Avatar
ncls.
That's different code now
Avatar
Sun bearOP
when i create new Socket
yes but error is same
when i create Socket
and add option cors
it says that the constructor doesnt exist
Avatar
ncls.
What version of socket.io are you using?
Avatar
Sun bearOP
"version": "4.7.2",
Avatar
ncls.
Hmm... Using the same version and following code works fine for me:
import express from 'express'
import http from 'http'
import { Server } from 'socket.io'

const app = express()
const server = http.createServer(app)

const io = new Server(server, {
  cors: {
    origin: '*'
  }
})
Maybe try it with an http server
Avatar
Sun bearOP
can you give me tsconfig
file
@ncls.
i am using pnpm, can this be problem?
Avatar
ncls.
Mostly default:
{
  "compilerOptions": {
    "target": "es2016",
    "module": "commonjs",
    "outDir": "./dist",
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "strict": true,
    "skipLibCheck": true
  }
}
Answer
Avatar
Sun bearOP
thanks
Avatar
ncls.
No idea. Try with NPM but I don't really think that should make a difference
Avatar
Sun bearOP
it works
Avatar
ncls.
Was it the Config?
Avatar
Sun bearOP
yes
Avatar
ncls.
Alright then