Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'
moonformeli opened this issue · 6 comments
Summary
What is your question?
// socket.ts
import { Server } from 'https://deno.land/x/sockets@v0.5.0/mod.ts';
const wss: Server = new Server();
wss.run({
hostname: '127.0.0.1',
port: 8081,
});
export { wss };
// index.ts
import { serve } from 'https://deno.land/std@0.83.0/http/server.ts';
import { wss } from './socket.ts';
const hostname = '127.0.0.1';
const server = serve({ hostname, port: 8080 });
console.log(`HTTP webserver running. Access it at: http://localhost:8080/`);
for await (const request of server) {
let bodyContent = 'Your user-agent is:\n\n';
bodyContent += request.headers.get('user-agent') || 'Unknown';
request.respond({ status: 200, body: bodyContent });
}
console.log(`Server started on ws://${wss.hostname}:${wss.port}`);
Run
deno run --allow-net index.ts
Result
This is a very simple example app in Deno.
But I faced that error when I tried to use this package.
What am I supposed to do to fix this?
typescript version: 4.1.3
deno version: 1.6.0
try importing from wocket
instead, as we changed the name, and wocket
will be the module we update from now on:
import { Server } from "https://deno.land/x/wocket@v0.6.2/mod.ts"
@ebebbington
Thanks, I don't see any errors now with importing wocket
, but I don't see any console log either
wss.run({
hostname: '127.0.0.1',
port: 8081,
});
console.log(`Server started on ws://${wss.hostname}:${wss.port}`);
Oh, I solved the problem!
The socket has to be opened before the web server is opened
Thank you for helping me :)
I wonder if I can use this package in my React app
I’m guessing you have a ws and http server running in the same file? Would you mind sharing the contents of that file? I’m just curious if you encountered a bug
and also no problem :) in relation to using it in your react application - you ‘could’, in the sense that Wocket would be your websocket server, then you can use the WebSocket API or https://github.com/drashland/socket-client to connect to it
Going to close this issue then