ts-belt not working in node environment?
Closed this issue ยท 7 comments
I have a project that I am creating with SvelteKit, ts-belt seems to work just fine on my client-side code:
if (browser) {
console.log(A.map([1, 2, 3], x => x + 2));
}
However, when I try to run it in on of the server-side files (i.e. +page.server.ts) it throws an error:
import { A } from '@mobily/ts-belt';
export const load: PageServerLoad = () => {
const arr = A.map([1, 2, 3], x => x + 1);
console.log(arr);
return {};
};
TypeError: Cannot read properties of undefined (reading 'A')
at load (.../src/routes/auth/register/+page.server.ts:23:13
I'm not sure if this is a SvelteKit issue, I haven't had that problem with any other library. Any ideas?
@bartektelec hello Bartek! ๐ could you provide a simple repro repo? (that would be helpful in debugging this problem)
https://github.com/bartektelec/tsbelt-server-test
made a repo to reproduce.
I tried creating one on codesandbox, but for some reason it seems to be working just fine there.
Locally, I tried yarn, pnpm and npm. I also tried running it through WSL2.
I also tried switching between node 16 and 18. No luck.
> tsbelt-server-test@0.0.1 dev
> vite dev
VITE v4.0.4 ready in 1725 ms
โ Local: http://localhost:5173/
โ Network: use --host to expose
โ press h to show help
(node:621) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
(Use `node --trace-warnings ...` to show where the warning was created)
TypeError: Cannot read properties of undefined (reading 'A')
at load (/mnt/d/projects/tsbelt-server-test/src/routes/+page.server.ts:5:27)
at Module.load_server_data (/node_modules/@sveltejs/kit/src/runtime/server/page/load_data.js:33:41)
at /node_modules/@sveltejs/kit/src/runtime/server/page/index.js:167:18
at processTicksAndRejections (node:internal/process/task_queues:96:5)
6:45:02 PM [vite-plugin-svelte] ssr compile in progress ...
6:45:03 PM [vite-plugin-svelte] ssr compile done.
package files time avg
tsbelt-server-test 3 24.3ms 8.1ms
thanks @bartektelec! and final question, do you use ts-belt v3
or v4
?
I used 3.13.1
@bartektelec could you check using the latest version v4.0.0-rc.5
? (yarn add @mobily/ts-belt@next
)
That solved the issue! ๐
@bartektelec that's great ๐ and sorry for the inconvenience!