Closed imjamesb closed 1 year ago
it looks like it's a duplicate of: https://github.com/tw-in-js/vscode-twind-intellisense/issues/10
i have read all of doc of twind for adding font from 'import' and 'font-face' it still doesn't work :(
it looks like it's a duplicate of: #10
Probably, there was not much info in #10 though.
It works when removing the selfURL property.
I think it has something to do with import.
being used.
Removing the selfURL
property from the config file seems to solve the issue:
@imjamesb
unfortunately still can't get it to work with the fix you mentioned above:
Have also restarted both Twind Intellisense and Deno lsp.
You cannot import $fresh
Try changing it to
/** @type {import("$fresh").Options} */
Right above the export, so it avoids the import entirely.
Ok, weird.
I tried your suggestion, but unfortunately it still didn't work.
However, since I no longer use the apply
function of Twind, Intellisense and also the linting works project-wide.
You are still importing $fresh
You cannot do that
Change it to:
/** @type {Omit<import("$fresh/plugins/twind.ts").Options, "selfURL">} */
export default {
// ...
As I said, I have already tried your suggestion:
Now that I define the preflight directly in the object, everything works:) Thank you!
May you could just trying remove fresh's import like import {} from "$fresh"
cause is that extension cannot load config (cause module $fresh
not found), so extension will use default config.
And if you import other things like twind/colors
, run npm install twind
first, when you reload intellisense, it will be work.
When extension load config, that will import config's dependencies from workspace's node_modules
(or other source file that in workspace), see loading module from node_modules.
Hope this comment can help you 😄.
Thanks @mooxl for showing your solution. Could you also shown your twind.config.ts file?
I'm using twind
with deno
and fresh version 1.1.
deno 1.25.0 (release, x86_64-pc-windows-msvc)
v8 10.6.194.5
typescript 4.7.4
This is my main.ts:
/// <reference no-default-lib="true" />
/// <reference lib="dom" />
/// <reference lib="dom.iterable" />
/// <reference lib="dom.asynciterable" />
/// <reference lib="deno.ns" />
import { start } from "$fresh/server.ts";
import manifest from "@/fresh.gen.ts";
import twindPlugin from "$fresh/plugins/twind.ts";
import twindConfig from "@/twind.config.ts";
await start(manifest, {
plugins: [
twindPlugin({
selfURL: new URL("./twind.config.ts", import.meta.url).href,
preflight: {},
...twindConfig,
}),
],
});
twind.config.ts:
import { Options } from "$fresh/plugins/twind.ts";
import * as colors from "twind/colors";
export default {
// selfURL: import.meta.url,
darkMode: "class",
mode: "silent",
theme: {
extend: {
colors,
},
},
} as unknown as Options;
I got this error in my main.ts:
The bg-sky-800
rule should be define in colors: import * as colors from "twind/colors";
in twind.config.ts.
Thanks @mooxl for showing your solution. Could you also shown your twind.config.ts file?
I'm using
twind
withdeno
and fresh version 1.1.deno 1.25.0 (release, x86_64-pc-windows-msvc) v8 10.6.194.5 typescript 4.7.4
This is my main.ts:
/// <reference no-default-lib="true" /> /// <reference lib="dom" /> /// <reference lib="dom.iterable" /> /// <reference lib="dom.asynciterable" /> /// <reference lib="deno.ns" /> import { start } from "$fresh/server.ts"; import manifest from "@/fresh.gen.ts"; import twindPlugin from "$fresh/plugins/twind.ts"; import twindConfig from "@/twind.config.ts"; await start(manifest, { plugins: [ twindPlugin({ selfURL: new URL("./twind.config.ts", import.meta.url).href, preflight: {}, ...twindConfig, }), ], });
twind.config.ts:
import { Options } from "$fresh/plugins/twind.ts"; import * as colors from "twind/colors"; export default { // selfURL: import.meta.url, darkMode: "class", mode: "silent", theme: { extend: { colors, }, }, } as unknown as Options;
I got this error in my main.ts:
The
bg-sky-800
rule should be define in colors:import * as colors from "twind/colors";
in twind.config.ts.
Hey, @gmunumel, the error means your selfURL
will be overwritten by ...twindConfig
because typeof twindConfig is Options
, Options
has property selfURL
.
Move selfURL
to under of ...twindConfig
like:
twindPlugin({
preflight: {},
...twindConfig,
selfURL: new URL("./twind.config.ts", import.meta.url).href,
});
Or you can change the twindConfig's type assert to Omit<Options, "selfURL">
, it will be work too.
To fix the second error (unknown utility "bg-sky-800"
), you could trying my solution. you cannot import $fresh
and twind/colors
in twind.config.ts
when your node_modules
haven't this two.
As @JuerGenie mentioned, you get an error because the typing is not right. Here are my two files:
main.ts
/// <reference no-default-lib="true" />
/// <reference lib="dom" />
/// <reference lib="dom.iterable" />
/// <reference lib="dom.asynciterable" />
/// <reference lib="deno.ns" />
import { start } from "$fresh/server.ts";
import manifest from "./fresh.gen.ts";
import { apply } from "twind";
import twindPlugin from "$fresh/plugins/twind.ts";
import twindConfig from "./twind.config.ts";
await start(manifest, {
plugins: [
twindPlugin({
selfURL: new URL("./twind.config.ts", import.meta.url).href,
preflight: {
"@font-face": [
{
fontFamily: "Plex",
src: 'url(/fonts/Plex-Regular.woff2) format("woff2")',
},
{
fontFamily: "Plex",
fontWeight: "bold",
src: 'url(/fonts/Plex-Bold.woff2) format("woff2")',
},
],
html: apply`text-html bg-gray`,
body: apply`text-sm text-white font-plex leading-none tracking-wide`,
},
...twindConfig,
}),
],
});
twind.config.ts
import { Options } from "$fresh/plugins/twind.ts";
export default {
theme: {
fontSize: {
html: "62.5%",
sm: "1.6rem",
md: "2.1rem",
lg: "3rem",
xl: "5rem",
},
fontWeight: {
bold: "700",
},
screens: {
lg: { max: "1040px" },
md: { max: "768px" },
sm: { max: "640px" },
},
fontFamily: {
plex: ["Plex", "sans-serif"],
},
maxWidth: {
xl: "1000px",
experience: "550px",
},
extend: {
colors: {
gray: {
DEFAULT: "#111111",
light: "#888888",
dark: "#222222",
},
},
gridTemplateColumns: {
desktop: "min-content auto",
},
},
},
} as Pick<Options, "theme">;
With this structure i get no linting and typing errors and the intellisense from Twind works:) @gmunumel
Thanks @JuerGenie and @mooxl, for your suggestions. Indeed the lint errors are gone. I only have the error with the custom css: unknown utility "bg-sky-800"
.
I tried to do the following with no luck (I'm using deno
and not node
, so not npm_modules
folder):
main.ts:
/// <reference no-default-lib="true" />
/// <reference lib="dom" />
/// <reference lib="dom.iterable" />
/// <reference lib="dom.asynciterable" />
/// <reference lib="deno.ns" />
import { start } from "$fresh/server.ts";
import manifest from "@/fresh.gen.ts";
import twindPlugin from "$fresh/plugins/twind.ts";
// import twindConfig from "@/twind.config.ts";
import * as colors from "twind/colors";
await start(manifest, {
plugins: [
twindPlugin({
selfURL: new URL("./twind.config.ts", import.meta.url).href,
preflight: {},
// ...twindConfig,
darkMode: "class",
// mode: "silent",
theme: {
extend: {
colors,
},
},
}),
],
});
import_map.json:
{
"imports": {
"@/": "./",
"$fresh/": "https://deno.land/x/fresh@1.1.1/",
"preact": "https://esm.sh/preact@10.11.0",
"preact/": "https://esm.sh/preact@10.11.0/",
"preact-render-to-string": "https://esm.sh/*preact-render-to-string@5.2.4",
"@preact/signals": "https://esm.sh/*@preact/signals@1.0.3",
"@preact/signals-core": "https://esm.sh/*@preact/signals-core@1.0.1",
"twind": "https://esm.sh/twind@0.16.17",
"twind/": "https://esm.sh/twind@0.16.17/",
"dotenv": "https://deno.land/x/dotenv@v3.2.0/load.ts",
"$std/": "https://deno.land/std@0.151.0/",
"statery": "https://esm.sh/statery@0.5.4?alias=react:preact/compat&deps=preact@10.8.2",
"jwt": "https://deno.land/x/djwt@v2.7/mod.ts"
}
}
I don't want to hijack this topic. May I open another ticket if you want to ;)
You have to define your theme in twind.config.ts
as show above. If you don't do that, twind doesn't recognise the custom theme
. Don't ask me why🙃 @gmunumel
Nop. Doesn't work for me. Still get the same error in my index.tsx.
main.ts:
/// <reference no-default-lib="true" />
/// <reference lib="dom" />
/// <reference lib="dom.iterable" />
/// <reference lib="dom.asynciterable" />
/// <reference lib="deno.ns" />
import { start } from "$fresh/server.ts";
import manifest from "@/fresh.gen.ts";
import twindPlugin from "$fresh/plugins/twind.ts";
import twindConfig from "@/twind.config.ts";
await start(manifest, {
plugins: [
twindPlugin({
selfURL: new URL("./twind.config.ts", import.meta.url).href,
preflight: {},
...twindConfig,
}),
],
});
twind.config.ts:
// import { Options } from "$fresh/plugins/twind.ts";
import * as colors from "twind/colors";
export default {
// selfURL: import.meta.url,
darkMode: "class",
mode: "silent",
theme: {
extend: {
colors,
},
},
// deno-lint-ignore no-explicit-any
} as Pick<any, "theme">;
Thanks @JuerGenie and @mooxl, for your suggestions. Indeed the lint errors are gone. I only have the error with the custom css:
unknown utility "bg-sky-800"
.I tried to do the following with no luck (I'm using
deno
and notnode
, so notnpm_modules
folder):main.ts:
/// <reference no-default-lib="true" /> /// <reference lib="dom" /> /// <reference lib="dom.iterable" /> /// <reference lib="dom.asynciterable" /> /// <reference lib="deno.ns" /> import { start } from "$fresh/server.ts"; import manifest from "@/fresh.gen.ts"; import twindPlugin from "$fresh/plugins/twind.ts"; // import twindConfig from "@/twind.config.ts"; import * as colors from "twind/colors"; await start(manifest, { plugins: [ twindPlugin({ selfURL: new URL("./twind.config.ts", import.meta.url).href, preflight: {}, // ...twindConfig, darkMode: "class", // mode: "silent", theme: { extend: { colors, }, }, }), ], });
import_map.json:
{ "imports": { "@/": "./", "$fresh/": "https://deno.land/x/fresh@1.1.1/", "preact": "https://esm.sh/preact@10.11.0", "preact/": "https://esm.sh/preact@10.11.0/", "preact-render-to-string": "https://esm.sh/*preact-render-to-string@5.2.4", "@preact/signals": "https://esm.sh/*@preact/signals@1.0.3", "@preact/signals-core": "https://esm.sh/*@preact/signals-core@1.0.1", "twind": "https://esm.sh/twind@0.16.17", "twind/": "https://esm.sh/twind@0.16.17/", "dotenv": "https://deno.land/x/dotenv@v3.2.0/load.ts", "$std/": "https://deno.land/std@0.151.0/", "statery": "https://esm.sh/statery@0.5.4?alias=react:preact/compat&deps=preact@10.8.2", "jwt": "https://deno.land/x/djwt@v2.7/mod.ts" } }
I don't want to hijack this topic. May I open another ticket if you want to ;)
It's ok, I'm using Deno too, but extension with VSCode was running on electron (based on NodeJS), so you know :D
Workaround -> https://github.com/tw-in-js/vscode-twind-intellisense/issues/10#issuecomment-1272295973
This will let you use the official tailwind extension instead
I had the same problem and put /** @type {Omit<import("$fresh/plugins/twind.ts").Options, "selfURL">} */
in twind.config.ts
helped me.
but the error keeps in the rest of the files.
how can I fix it?
twind.config.ts
main.ts
Some component e8e7a5280446.png)
I had the same problem and put /** @type {Omit<import("$fresh/plugins/twind.ts").Options, "selfURL">} */
in twind.config.ts
helped me.
but the error keeps in the rest of the files.
how can I fix it?
twind.config.ts
main.ts
Some component
twind config
Logs: