-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to configure for Typescript #3
Comments
@khashashin Thank you for submitting this issue and thank you for bringing this to my attention. Please see privatenumber/tsx#354 and nodejs/node#47747 for more information on this issue. The following approach, as described in vitest-dev/vitest#5757 (comment), seems to work; however, I don't know all the implications of using it. import * as net from 'node:net';
import { createServiceProxy, Level } from 'socketnaut';
const server = net.createServer();
server.listen({ port: 8080, host: '0.0.0.0' });
const proxy = createServiceProxy({
server,
minWorkers: 4,
maxWorkers: 42,
workerURL: `import { tsImport } from "tsx/esm/api"; tsImport("./app.ts", import.meta.url);`,
workerOptions: { eval: true }
}); The |
Thank you so much for your prompt response and for providing a workable solution! I implemented your suggested approach and made a few additional tweaks to accommodate both development and production environments. Specifically, I encountered an issue where the relative path was being resolved relative to Here is my final import path from "path";
import { createServer, Server } from "node:net";
import { fileURLToPath, pathToFileURL } from "url";
import { createServiceProxy, Level } from "socketnaut";
const isProduction = process.env.NODE_ENV === "production";
const workerFile = isProduction ? "app.js" : "app.ts";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const workerPath = pathToFileURL(path.resolve(__dirname, workerFile)).href;
const server: Server = createServer();
server.listen({ port: 8080, host: "0.0.0.0" }, () => {
console.log("Server listening on port 8080");
});
const proxy = createServiceProxy({
server,
minWorkers: 4,
maxWorkers: 42,
workerURL: `import { tsImport } from "tsx/esm/api"; tsImport("${workerPath}", import.meta.url);`,
workerOptions: { eval: true },
});
proxy.log.setLevel(isProduction ? Level.INFO : Level.DEBUG); It works using the following Docker image: FROM node:22-alpine AS builder
WORKDIR /app
COPY package.json package-lock.json tsconfig.json ./
RUN npm ci
COPY src ./src
RUN npm run build
FROM node:22-alpine
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm install
COPY --from=builder /app/dist ./dist
ENV NODE_ENV=production
EXPOSE 8080
CMD ["node", "dist/index.js"] |
Can this package be used in typescript project? Doing the following does not work
The error
The text was updated successfully, but these errors were encountered: