-
-
Notifications
You must be signed in to change notification settings - Fork 163
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
Can't make it work with Vite/Svelte #812
Comments
Did you follow this guide? https://typia.io/docs/setup/#vite |
Yes I did. That's what I meant when I wrote this:
|
I am also seeing similar problems. I am using vite version: |
I think I may have found the source of the problem: typia/src/programmers/TypiaProgrammer.ts Line 159 in 3776b11
Because your file ends with |
@matthew-dean Could you give PR #816 a try? It's a very simple fix. I did a quick and dirty test on my own machine and it seemed to work, but I am using React and not Svelte... |
@howesteve @tsengia Will you svelte generation with As I don't know svelte at all, cannot sure it to work. npm install --save typia@next |
Tried but not working on |
@samchon Even with latest fix still can't get it to work with react. I had to modify/hot patch
I have a hunch that maybe toying with the Vite plugin settings may fix this, possibly by changing the plugin ordering. On another note, generation with |
Update: Essentially, I had to cut Vite and the import { defineConfig } from "vite";
import typescript from "rollup-plugin-typescript2";
import tspCompiler from "ts-patch/compiler";
// https://vitejs.dev/config/
export default defineConfig({
plugins: [{...typescript({
typescript: tspCompiler,
sourceMap: true,
inlineSources: true
}), enforce:"post"}],
esbuild: false,
// Vite options tailored for Tauri development and only applied in `tauri dev` or `tauri build`
//
// 1. prevent vite from obscuring rust errors
clearScreen: false,
// 2. tauri expects a fixed port, fail if that port is not available
server: {
port: 1420,
strictPort: true,
},
// 3. to make use of `TAURI_DEBUG` and other env variables
// https://tauri.studio/v1/api/config#buildconfig.beforedevcommand
envPrefix: ["VITE_", "TAURI_"],
}); Additionally, my "compilerOptions": {
"target": "ES2020",
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"module": "ESNext",
"skipLibCheck": true,
/* Bundler mode */
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsxdev",
/* Linting */
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true,
/* Needed for mobx */
"useDefineForClassFields": true,
/* Needed for typia */
"plugins": [
{ "transform": "typia/lib/transform" }
]
}, Note: Please ignore the With these settings, I was able to get my React app to be transformed + transpiled to JavaScript, however the resulting One good thing about using the |
I'm also facing this issue, with Vite's react template. I face this error when trying to start the dev server:
My tsconfig looks like this:
And my vite config is the same as what's used in the documentation:
The issue seems to be caused by
This seems to make it virtually impossible to use with the react vite plugin, because the
|
I forgot to mention, when I got Typia to work in my above comment, I had to modify the |
@tsengia how did you do this? did you modify the source or how else did you achieve it? |
I use Typia with SvelteKit (+ MDsveX) and din't need to modify any code. My vite.config.ts is like the Docs says: import { sveltekit } from '@sveltejs/kit/vite';
import { defineConfig } from 'vite';
import typescript from "rollup-plugin-typescript2" // @rollup/plugin-typescript";
export default defineConfig({
esbuild: false,
plugins: [ sveltekit(), typescript()]
}); Typia is not working inside *.svelte files. But on *.ts files that can be imported. My Workaround looks like this: // Example.ts
import typia, { tags } from "typia";
export type Example = {
Id: string & tags.MinLength<12>;
Date: string & tags.Format<"date">;
editable: boolean;
}
export const ExampleToJson = typia.json.createAssertStringify<Example>();
export const ExampleFromJson = typia.json.createAssertParse<Example>();
export const ExampleWithRandomData: Example = typia.random<Example>(); <script lang="ts">
import type { Example } from '$lib/Example';
import { ExampleToJson, ExampleWithRandomData } from '$lib/Example';
let example: Example = ExampleWithRandomData;
let json = '';
try {
json = ExampleToJson(example);
} catch (error) {
console.error(error);
}
console.log(example);
</script>
{json} Only that Typia isn't type-safe if i use it with classes (see #683 ) causes me headaches. |
Experiencing this problem too. Would love to use typia for svelte but I spent 30 minutes & still can't make it work so will wait for V5. |
Note : on a new Sveltekit deployment, I had to pass in the check: false arguments in vite.config.ts to stop the rollup plugin blocking the dev
As it was raising a crazy amount of errors It worked on Typescript files in the svelte repo so Typia can be used with sveltekit BUT I then tried on a Turborepo and it did not work for other workspaces TS files (issue submitted here: ezolenko/rollup-plugin-typescript2#465) |
@MarArMar Do you need pnpm-workspaces? Without it I can use TS. Try this: And I don't need |
Ok here is a working example : Turborepo X Sveltekit X Typia Main thing was the vite config : import { sveltekit } from "@sveltejs/kit/vite";
import { defineConfig } from "vite";
import typescript from "rollup-plugin-typescript2";
export default defineConfig({
// esbuild: false,
plugins: [
sveltekit(),
typescript({
check: false,
}),
],
}); Have to not set esbuild: false else loading of workspace modules in ts do not work Sidenote : I tested using typia in modules outside svelte imported in svelte, not sure it works within svelte files, but was good enough for me to be able to make wrappers outside of svelte & import them |
@a-kla Unfortunaltely it didn't work for me : in export default defineConfig({
// esbuild: false,
plugins: [
sveltekit(),
typescript({
// check: false,
sourceMap: false,
}),
],
}); Makes the page a 500 error, If I do : export default defineConfig({
// esbuild: false,
plugins: [
sveltekit(),
typescript({
check: false,
sourceMap: false,
}),
],
}); I can see the page but Typia seems to be not working when imported from a ts file : "true (expected: true) & notMatched is true (expected: false)" It does not change anything if I add in {
"compilerOptions": {
"sourceMap": false,
"checkJs": false,
}
} Finally if I add the "esbuild: false," in My repo : https://github.com/MarArMar/TurboSvelteKitTypia |
I am desperatly trying to make this work : https://github.com/MarArMar/TurboSvelteKitTypia How did you manage to modify/hot patch the Update : Actually it might not be that at all, my problem is with importing ts files, not tsx files.. |
My patch is not in Typia; it was a local patch I did to I believe the patch involved modifying this function so that when Currently, Later next week I'll be able to dig through my files again to get you an absolute answer, but right now I'm away from the PC that I used to perform this patch so I don't have the exact code I used on hand. |
I found out that this works well in my Project: /// <reference types="@sveltejs/kit" />
import { sveltekit } from '@sveltejs/kit/vite';
import { defineConfig } from 'vitest/config';
// for Typia
import typescript from "rollup-plugin-typescript2"
export default defineConfig({
plugins: [
{
enforce: 'pre', // <= this line fixes all my initial problems
...typescript(),
},
sveltekit(),
],
}); Now I have no changes in my tsconfig.json, except the one the Setup Wizard added automatically. ! Important Note: |
@a-kla Thank you so much for your answer ! managed to finally make it work with this in vite.config.ts : " include: ["../../**/*.ts+(|x)"]," |
I'm using an ESM package and no matter how I tried this, even using the overrides for the tsconfig it would just break subsequent code. The easiest way is to add in a generate function you trigger manually ( Then have all your code point to that registered code. (don't forget to get eslint to forget about it too if its in your
This works well. You still get the decorator creation in tsc which isn't really needed right now but the generate works well and now have no issues with all the weirdness you get with vitest and esbuild getting in the way. |
If some of you have knowhow about this issue, please send a website PR please. |
If you also experience "TypeError: Cannot read properties of undefined (reading 'add')" for using typia with vite & rollup-plugin-typescript2, I have this issue opened : With a reproduction repo for those who might have fixed the problem already : Will update on fix & welcoming help |
Hi https://github.com/ryoppippi/unplugin-typia/tree/main/packages/unplugin-typia @MarArMar |
Will try and give feedback probably next week, thanks so much @ryoppippi !! 😀 |
@MarArMar |
@samchon |
@ryoppippi thanks for the script !!! Could not manage to use typia correctly before, I got it to work correctly in a monorepo, also with sourcemaps, meaning the browser & server debugger also functions correctly ✅ |
@MarArMar |
Hello. I'd love to test this, but I just can't make it work with Vite. Tried for days, and nothing. It always throws:
I followed the setup guide, tried the
npx typia setup
method, the manual installation, and no deal.I've created my test repo using these steps:
I checked, and the transformer plugin is in place:
Until here, project loads normally. Then when I edit
App.svelte
to include:and as I save, immediately, the error above is thrown.
I've uploaded my repository into here:
https://github.com/howesteve/typia-test/
Any clues? Is there any bare-bones repository of this actually running with vite?
Thanks.
The text was updated successfully, but these errors were encountered: