-
Hi folks, I started getting erorrs in my browser app: Which makes sense, there is no process in the browser, that is a NodeJS environment. import { io } from 'socket.io-client';
import type { Socket } from 'socket.io-client';
export const getSockClient = (auth: Record<string, string>): Socket<any, any> =>
io({
auth,
autoConnect: false,
transports: ['websocket'],
path: '/ws' // my server is at this path instead of default /socket.io
}); I tried many things to resolve this, but the only thing that helped is using /// <reference types='vitest' />
import { defineConfig, searchForWorkspaceRoot } from 'vite';
import { svelte } from '@sveltejs/vite-plugin-svelte';
import { nodePolyfills } from 'vite-plugin-node-polyfills';
import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin';
export default defineConfig({
root: __dirname,
build: {
outDir: '../../../dist/apps/ui/chat',
reportCompressedSize: true,
commonjsOptions: {
transformMixedEsModules: true,
},
},
cacheDir: '../../../node_modules/.vite/chat',
server: {
port: 4200,
host: 'localhost',
fs: {
allow: [searchForWorkspaceRoot(process.cwd())],
},
proxy: {
'/api': {
target: 'http://localhost:3000/',
changeOrigin: true,
secure: false,
ws: true,
configure: (proxy) => {
proxy.on('proxyReq', (proxyReq, req, res) => {
const hostname = req.headers.host?.split(':')[0] || '';
proxyReq.setHeader('host', hostname);
});
},
},
'/ws/': {
target: 'http://localhost:3000/',
changeOrigin: true,
secure: false,
ws: true,
},
},
},
preview: {
port: 4300,
host: 'localhost',
},
plugins: [
svelte(),
nxViteTsPaths(),
nodePolyfills({
include: ['process'],
}),
],
// Uncomment this if you are using workers.
//worker: {
// plugins: [ nxViteTsPaths() ],
//},
test: {
reporters: ['default'],
coverage: {
reportsDirectory: '../../../coverage/apps/ui/chat',
provider: 'v8',
},
globals: true,
cache: {
dir: '../../../node_modules/.vitest',
},
environment: 'jsdom',
include: ['src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
},
}); Now my app loads, but it fails to connect to the socket.io server with error thanks! versions:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
updating |
Beta Was this translation helpful? Give feedback.
updating
vite
and@sveltejs/vite-plugin-svelte
to latest seems to have resolved the issue...