S
SolidJSโ€ข2y ago
siduck

solid-jsx not working

Error [ERR_REQUIRE_ESM]: require() of ES Module /home/sid/my-app/node_modules/@mdx-js/rollup/index.js from /ho me/sid/my-app/vite.config.js not supported.
150 Replies
siduck
siduckOPโ€ข2y ago
@.high1 any idea? my vite config
import { defineConfig } from "vite";
import solidPlugin from "vite-plugin-solid";

import mdx from "@mdx-js/rollup";

export default defineConfig({
plugins: [solidPlugin(), mdx({ jsxImportSource: "solid-jsx" })],
server: {
port: 3000,
},
build: {
target: "esnext",
},
});
import { defineConfig } from "vite";
import solidPlugin from "vite-plugin-solid";

import mdx from "@mdx-js/rollup";

export default defineConfig({
plugins: [solidPlugin(), mdx({ jsxImportSource: "solid-jsx" })],
server: {
port: 3000,
},
build: {
target: "esnext",
},
});
siduck
siduckOPโ€ข2y ago
Brendan
Brendanโ€ข2y ago
Have you got "type": "module" in your package.json?
siduck
siduckOPโ€ข2y ago
oh cool the error is gone now!
Brendan
Brendanโ€ข2y ago
Feel free to close this thread if your query is resolved. Perhaps open another one if you have a different question.
high1
high1โ€ข2y ago
Thanks, @brendan_csel . There's a section dedicated to this in the beginning of the README file, Use mdx or xdm with solid-js. This module is ESM only, due to mdx and xdm being ESM only. Adding "type": "module" in package.json is one option.
siduck
siduckOPโ€ข2y ago
i tried this but i get some postcss error now
siduck
siduckOPโ€ข2y ago
high1
high1โ€ข2y ago
Well, if your project is a module, you need to be explicit it's postcss.config.cjs if you are writing common JS Or use a more modern syntax and postcss.config.js or mjs
siduck
siduckOPโ€ข2y ago
i renamed the file and i get this error now
siduck
siduckOPโ€ข2y ago
high1
high1โ€ข2y ago
It's the same issue. You really need to read ๐Ÿ˜„ these error messages. Just name it tailwind.config.cjs If something uses module.exports..., it's cjs
siduck
siduckOPโ€ข2y ago
oh i changed the syntax for both the files but i get the same error!
high1
high1โ€ข2y ago
You can use export default for tailwind and postcss, if you prefer that What did you do exactly?
siduck
siduckOPโ€ข2y ago
high1
high1โ€ข2y ago
If your files are using module.exports, name them .cjs
siduck
siduckOPโ€ข2y ago
renaming both of them to cjs works! thanks
high1
high1โ€ข2y ago
It's not that renaming works, it's that you're confused with cjs and mjs syntax, and you have every right to be... It's an issue inherited from common js modules used by Node before the proper JS module specification So, I recommend that you use those only when nothing else works This one would work if it was named tailwind.config.mjs postcss needs imports there If you're using vite, I don't think you need postcss I think you probably are
high1
high1โ€ข2y ago
GitHub
GitHub - unocss/unocss: The instant on-demand atomic CSS engine.
The instant on-demand atomic CSS engine. Contribute to unocss/unocss development by creating an account on GitHub.
high1
high1โ€ข2y ago
Also It's faster than tailwind, and has a better VSCode plugin, IMHO There's a sample repo which demonstrates solid SVG clock here
high1
high1โ€ข2y ago
GitHub
GitHub - high1/solid-clock: sauron clock in solid-js
sauron clock in solid-js. Contribute to high1/solid-clock development by creating an account on GitHub.
high1
high1โ€ข2y ago
Uses unocss, Vite, TypeScript There's also ESLint config Could be a nice start if you're not too far along Yeah, Prettier also
siduck
siduckOPโ€ข2y ago
faster in build time? also i dont use vscode so the vscode plugin wont matter to me :p
high1
high1โ€ข2y ago
It has a faster engine, and has all the optimizations that Tailwind has
siduck
siduckOPโ€ข2y ago
does it have a lsp?
high1
high1โ€ข2y ago
Don't think so And you don't need to mess with postcss Unless you really need to
siduck
siduckOPโ€ข2y ago
GitHub
GitHub - xna00/unocss-language-server
Contribute to xna00/unocss-language-server development by creating an account on GitHub.
siduck
siduckOPโ€ข2y ago
ok i can use this with neovim!
high1
high1โ€ข2y ago
You're on your own there
siduck
siduckOPโ€ข2y ago
dont worry about that, ive used custom lsps in neovim before
high1
high1โ€ข2y ago
If you have ESLint and Prettier working in Neovim, I'd be curious too see that
siduck
siduckOPโ€ข2y ago
that works since ages lul
high1
high1โ€ข2y ago
Typescript type check also?
siduck
siduckOPโ€ข2y ago
yes tsserver works in neovim so almost all vscode lsps will work in neovim too
siduck
siduckOPโ€ข2y ago
GitHub
GitHub - neovim/nvim-lspconfig: Quickstart configs for Nvim LSP
Quickstart configs for Nvim LSP. Contribute to neovim/nvim-lspconfig development by creating an account on GitHub.
high1
high1โ€ข2y ago
Hm, I would really love to have my setup from solid-clock repo transfered to neovim
siduck
siduckOPโ€ข2y ago
i install all the lsp/formatter/linter/debugger etc binaries from mason.nvim plugin
siduck
siduckOPโ€ข2y ago
incase you're curious about my config, this is it https://github.com/NvChad/NvChad ๐Ÿ˜„
GitHub
GitHub - NvChad/NvChad: An attempt to make neovim cli functional li...
An attempt to make neovim cli functional like an IDE while being very beautiful, blazing fast startuptime - GitHub - NvChad/NvChad: An attempt to make neovim cli functional like an IDE while being...
high1
high1โ€ข2y ago
Huh, it's a world for itself... Not sure if I want to dive that deep inside
siduck
siduckOPโ€ข2y ago
you dont have to start from a full blown config first make your own
siduck
siduckOPโ€ข2y ago
TJ DeVries
YouTube
Effective Neovim: Instant IDE
Going from no set up to instant IDE using kickstart.nvim in #nvim. Check out the repo: https://github.com/nvim-lua/kickstart.nvim PDE Video: https://youtu.be/QMVIJhC9Veg Twitch We're always live streamin on twitch!Twitch : https://twitch.tv/teej_dv Discord: https://discord.gg/h2yeg4wrSK Links Twitch: https://twitch.tv/teej_dv Twitter...
siduck
siduckOPโ€ข2y ago
ThePrimeagen
YouTube
0 to LSP : Neovim RC From Scratch
I setup the entire neovim experience from nothing to LSP! REPO: https://github.com/ThePrimeagen/init.lua chapters 00:00 Introduction 00:35 Init.lua - Your First Files 02:23 The First Remap 03:43 Plugin Manager and Fuzzy Finder 07:07 Colorscheme 09:08 Treesitter 13:30 3 Must Have Plugins 18:06 LSP Setup 21:33 Editor Settings 24:24 THE BEST ...
siduck
siduckOPโ€ข2y ago
btw can I use unocss classes in css files?
siduck
siduckOPโ€ข2y ago
i do it a lot with tailwind
high1
high1โ€ข2y ago
Yes, there's apply also
high1
high1โ€ข2y ago
GitHub
unocss/packages/transformer-directives at main ยท unocss/unocss
The instant on-demand atomic CSS engine. Contribute to unocss/unocss development by creating an account on GitHub.
high1
high1โ€ข2y ago
Your config should be working OOTB, unless you're using typography preset
siduck
siduckOPโ€ข2y ago
wew looks cool! will try it out ๐Ÿ˜„
high1
high1โ€ข2y ago
Only things that you will need to do is move theme config from theme: { extend: { ... } } to just theme: { } And to uno.config.ts file
siduck
siduckOPโ€ข2y ago
thx i'll do the change today! btw how do i highlight the code tags which are in the jsx generated by solid-jsx? i tried using prism-js but didnt work
high1
high1โ€ข2y ago
You can check out how it's done on solid-js site - there are other things you need to set for code highlightning
siduck
siduckOPโ€ข2y ago
solid-js site uses solid-jsx? ive used highlightjs with solid-marked before,worked fine
siduck
siduckOPโ€ข2y ago
this works but there's 1 sec delay ๐Ÿ˜ฆ
siduck
siduckOPโ€ข2y ago
without settimeout it doesnt work
createEffect(() => {
document.querySelectorAll("pre code").forEach((el) => {
console.log(el)
});
});
createEffect(() => {
document.querySelectorAll("pre code").forEach((el) => {
console.log(el)
});
});
that doesnt print anything, doesnt createEffect run after component has been rendered?
siduck
siduckOPโ€ข2y ago
with solid-marked, i was able to set highlight to code elements after they rendered
high1
high1โ€ข2y ago
You're not doing it correctly. Solid-site uses solid-mdx, but it doesn't matter what's used since this is a matter of mdx-js configuration.
siduck
siduckOPโ€ข2y ago
hmm then how do I add the highlight stuff to all code elements at compile time? is it possible?
high1
high1โ€ข2y ago
It is, it works that way on solid-site import rehypeHighlight from 'rehype-highlight'; Do you have that in your mdx-js config?
siduck
siduckOPโ€ข2y ago
no
high1
high1โ€ข2y ago
I told you to look at the code. ma ๐Ÿ˜„ rehypePlugins: [rehypeHighlight], }),
siduck
siduckOPโ€ข2y ago
didnt know there was a mdx-js config! whats the difference between solid-mdx and solid-jsx?
high1
high1โ€ข2y ago
There is - you should read the festive manual ๐Ÿ˜„
siduck
siduckOPโ€ข2y ago
i tried from the solid-jsx readme, couldnt find anything syntax highlight related ๐Ÿค”
high1
high1โ€ข2y ago
The difference is that solid-jsx works over jsx function and fixes some of the issues that you can encounter due to solid differently dealing with elements than react solid-mdx just precreates and exports basic components, so that they are there when imported The difference is also that solid-mdx compiles to jsx, and that jsx goes through solid, so if you have a component inside mdx itself, it would be reactive. But why would you write a component inside mdx, I'm not sure.
siduck
siduckOPโ€ข2y ago
wew thx just including this worked!
high1
high1โ€ข2y ago
you could have issues when building The instructions for highlight plugins are not in solid-jsx docs, it belongs to @md9742x-js
siduck
siduckOPโ€ข2y ago
also does rehype provide a css file for the syntax classes?
high1
high1โ€ข2y ago
You can have custom theming there's hljs.css on solid-site
siduck
siduckOPโ€ข2y ago
is there a default one?
high1
high1โ€ข2y ago
You could basically download a custom theme, and just add that to your css I'm not sure about the defaults...
siduck
siduckOPโ€ข2y ago
oh no wonder my previous theme file from highlight.js worked ๐Ÿ˜„
high1
high1โ€ข2y ago
yep
high1
high1โ€ข2y ago
GitHub
solid-site/hljs.css at main ยท solidjs/solid-site
Code that powers the SolidJS.com platform. Contribute to solidjs/solid-site development by creating an account on GitHub.
high1
high1โ€ข2y ago
Here's what solid uses There's also some theming there for markdown prose That you don't need
siduck
siduckOPโ€ข2y ago
btw @.high1 is it possible to run code whenever the elements in outlet from solidjs-router change? or at route change
high1
high1โ€ข2y ago
It should be
siduck
siduckOPโ€ข2y ago
this works
siduck
siduckOPโ€ข2y ago
but if i remove printing of location.pathname then it stops working cant i include location.pathname in array of createeffect?
high1
high1โ€ข2y ago
Yes, because the effect does not know that it should run you could use on createEffect(on(() => location.pathname, { your code ... })); If you need to explicitly depend on something But that almost always points that you're not doing it right
siduck
siduckOPโ€ข2y ago
oh solid's createEffect works differently
high1
high1โ€ข2y ago
How do you mean differently? It works exactly as it should, unlike React ones ๐Ÿ˜„ effects knows their deps, and rerender accordingly
siduck
siduckOPโ€ข2y ago
i assumed it'd had that array of dependencies too, like react ๐Ÿ˜„
high1
high1โ€ข2y ago
Read the festive docs There's no array of deps, and components do not rerender, in fact, they dissappear There's quite a bit to process, I'll give you that
siduck
siduckOPโ€ข2y ago
i did before, its easy to forget when I work with react/solid on the same day!
high1
high1โ€ข2y ago
Yep,
siduck
siduckOPโ€ข2y ago
you sure this is the right syntax?
siduck
siduckOPโ€ข2y ago
high1
high1โ€ข2y ago
Not 100% percent, but it's there
siduck
siduckOPโ€ข2y ago
or On's a function in solidjs module?
high1
high1โ€ข2y ago
You need to import on, first yep
high1
high1โ€ข2y ago
SolidJS
Solid is a purely reactive library. It was designed from the ground up with a reactive core. It's influenced by reactive principles developed by previous libraries.
siduck
siduckOPโ€ข2y ago
i imported it, i get the same error
siduck
siduckOPโ€ข2y ago
high1
high1โ€ข2y ago
Your code also needs to be a function on(() => location.pathname, () => { ... })
siduck
siduckOPโ€ข2y ago
oh got it, i was using your previous code. thx for all the help!
high1
high1โ€ข2y ago
np, keep on pushing...
siduck
siduckOPโ€ข2y ago
btw solid-js compiles all the jsx stuff to vanilla js right? then why is it not a devdependency? i put it and solid-router as devdependcy, it still works :0 tried out unocss today, its quite fast! but i dont get any completions at all in vscode ( installed unocss extension ) however i do get some completions in neovim
siduck
siduckOPโ€ข2y ago
siduck
siduckOPโ€ข2y ago
siduck
siduckOPโ€ข2y ago
where vscode shows no completions at all :/
siduck
siduckOPโ€ข2y ago
nvm i give up man tailwind might be bloated as compared to this but it has a good community support & lsp too nvm fixed it this doesnt work
siduck
siduckOPโ€ข2y ago
btw @.high1 can i select multiple child elements with unocss?
siduck
siduckOPโ€ข2y ago
and the same thing works on the playground
siduck
siduckOPโ€ข2y ago
my unoconfig contains the same presets as the playground btw
import transformerAttributifyJsx from "@unocss/transformer-attributify-jsx";

import {
defineConfig,
presetAttributify,
presetUno,
} from 'unocss'

export default defineConfig({
presets: [
presetUno(),
presetAttributify(),
],
transformers: [
transformerAttributifyJsx(),
],
});
import transformerAttributifyJsx from "@unocss/transformer-attributify-jsx";

import {
defineConfig,
presetAttributify,
presetUno,
} from 'unocss'

export default defineConfig({
presets: [
presetUno(),
presetAttributify(),
],
transformers: [
transformerAttributifyJsx(),
],
});
high1
high1โ€ข2y ago
same as you would do it in tailwind I think there's group-focus, group:hover etc.
siduck
siduckOPโ€ข2y ago
[&>:bg-red] doesnt work at all but `[&>]:bg-red` works in the playground
high1
high1โ€ข2y ago
Not sure about custom selectors If it doesn't work, there's a special rule in the playground for that, you just need to copy it inside your config The rules are basically regexes Most of the time, you can just add things that you need
siduck
siduckOPโ€ข2y ago
no such rule in the playground config
high1
high1โ€ข2y ago
Then it must work in your code also
siduck
siduckOPโ€ข2y ago
it doesnt, thats why i asked it here
high1
high1โ€ข2y ago
I would need to see your config
siduck
siduckOPโ€ข2y ago
here
<div bg-lime p-5 class="[&>p]:bg-red">
<p> kek</p>
</div>
<div bg-lime p-5 class="[&>p]:bg-red">
<p> kek</p>
</div>
high1
high1โ€ข2y ago
Not sure why that doesn't work Where's the playground link? Also, I'm noticing that it's not underlined, so uno is not recognising it
high1
high1โ€ข2y ago
You see that the rule is not recognized? It's not underlined
siduck
siduckOPโ€ข2y ago
yep then why does it work?
high1
high1โ€ข2y ago
Uno does not recognize it You'll have to look or ask on their GitHub for arbitrary selectors syntax, haven't used it But bg-lime and p-5 are underlined So, you see that these are recognized Your arbitrary selector is not
siduck
siduckOPโ€ข2y ago
yes
high1
high1โ€ข2y ago
Why does it work in that specific case, I don't know It's something with the playgrond But it's not recognized and it will not work
siduck
siduckOPโ€ข2y ago
is there any other way through which i could select? like selecting all p elements in parent div
high1
high1โ€ข2y ago
This works for me [&_p]:bg-red It will be underlined
siduck
siduckOPโ€ข2y ago
oh doesnt work locally for me ://
siduck
siduckOPโ€ข2y ago
do i need a preset for this?
high1
high1โ€ข2y ago
You don't it's arbitrary
siduck
siduckOPโ€ข2y ago
ughh man then what could go wrong
high1
high1โ€ข2y ago
It works for me
high1
high1โ€ข2y ago
siduck
siduckOPโ€ข2y ago
:((
high1
high1โ€ข2y ago
With auto completion Now I'm not aware of the syntax for those, but you can always ask
siduck
siduckOPโ€ข2y ago
can you check if it works on this project? the starter project is very minimal ( just for testing )
high1
high1โ€ข2y ago
Can't you put that on code sandbox or
siduck
siduckOPโ€ข2y ago
Ok lemme try
high1
high1โ€ข2y ago
high1
high1โ€ข2y ago
high1
high1โ€ข2y ago
Svelte
high1
high1โ€ข2y ago
So, looks like an issue in Solid to me That's one downside -this custom JSX transformation causes issues sometimes, the another one is no destructuring...
siduck
siduckOPโ€ข2y ago
oh :((
high1
high1โ€ข2y ago
You can open an issue, though It'll be fixed in 1.6.7, I hope
REEEEE
REEEEEโ€ข2y ago
oop nvm I see what you mean
siduck
siduckOPโ€ข2y ago
done also custom classes dont work on break points for example
.custom-div {
@apply text-center bg-red;
}
.custom-div {
@apply text-center bg-red;
}
lg:custom-div this doesnt work like that of in tailwind
siduck
siduckOPโ€ข2y ago
GitHub
unocss/packages/transformer-directives at main ยท unocss/unocss
The instant on-demand atomic CSS engine. Contribute to unocss/unocss development by creating an account on GitHub.
high1
high1โ€ข2y ago
huh, that's not good... But that's an issue in unocss, right? @siduck_og, I've tried, but tailwind also does not apply custom classes on breakpoints, at least not on their playground
high1
high1โ€ข2y ago
Tailwind Play
Tailwind Play
An advanced online playground for Tailwind CSS that lets you use all of Tailwind's build-time features directly in the browser.
siduck
siduckOPโ€ข2y ago
yes most likely it works for me, try this
@layer base {
.custom-div {
@apply flex text-yellow-500;
}
}
@layer base {
.custom-div {
@apply flex text-yellow-500;
}
}
siduck
siduckOPโ€ข2y ago
Tailwind Play
Tailwind Play
An advanced online playground for Tailwind CSS that lets you use all of Tailwind's build-time features directly in the browser.
siduck
siduckOPโ€ข2y ago
@.high1 that wasnt a bug in solid, loading unocss plugin before solidplugin in vitejs config fixes this ๐Ÿ˜„
siduck
siduckOPโ€ข2y ago
GitHub
Custom selectors not working only on solidjs ( unocss ) ยท Issue #14...
Describe the bug hi there, Im using unocss and i use this syntax to add classes for all span elements in a div [&amp;_span]:bg-red , this will add bg-red to all span elements of the parent div ...
high1
high1โ€ข2y ago
Hm, I don't see why would custom transform change the class string? It's a liability... But it's solved.
Want results from more Discord servers?
Add your server