-
Notifications
You must be signed in to change notification settings - Fork 114
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
ES Module support #92
Comments
Hi @rogden, Any news on this? We really like to have this in our base theme, but we use |
@stijns96 Is the root of the issue a tailwind config using .mjs extension and/or when a tailwind config is using import statements? |
@rogden I don't think so. In using Vite the tailwind config file is using export default {} instead of module.exports and it fails when the code tries to import the tailwind config using require(); |
That's true! |
Thanks for the responses. I have a fix I'm testing. Should have it published this weekend. Going to need to require node 13.2+ which shouldn't be an issue given 18 current oldest LTS. I suppose it will need to be v2 since it is technically a breaking change if you are running Node < 13.2. |
Thanks |
If you need a bit more information on the error, here is the output when I try to open the config viewer in the browser:
|
@rogden what is the status? |
Also awaiting these changes |
Is there a workaround ? |
Thanks for the reply @rogden ! I take this opportunity to describe my scenario, hoping that it can be used by more folks as well and this usage can be considered for further development of this package.
Scenario - Multiple Tailwind ConfigsI have a "chain" of tailwind configs merged into a final config. Because of that, it's not enough unfortunately rewriting the final taiwlindConfig (which is used by A partial workaroundYesterday i tried to find a workaround, and i think that i most case it will work. # install esbuild
npm i -D esbuild then add scripts /* package.json */
scripts: {
"ds:tailwind:config-viewer:compile": "esbuild ./tailwind.config.ts --bundle --format=cjs --outfile=dist-tw-config/tailwind.config.cjs --platform=node",
"ds:tailwind:config-viewer": "npm run ds:tailwind:config-viewer:compile && tailwind-config-viewer -c dist-tw-config/tailwind.config.cjs -o -p 9000"
} Then run
I'm my case this workaround is not working, but i presume because of a npm package that i use that is not compatible. |
Just published v2. It should fix your ESM issues. Let me know if you run into any new issues related to it. @tresorama Let me know if it solves your issue as well. |
After updating to 2.0.0 i tried, and it doesn't crash! But the Vue app shows the default tailwind config and not mine, so i suppose that is because i use a chain of configs (with plugins also), but I didn't test enough to confirm this... I'm doing tailwind-config-viewer -c ./tailwind.config.ts -o -p 3003 // in ./tailwind.config.ts
import { Config } from "tailwindcss";
export default {
presets: [
require("./src/ds/tailwind/tailwind.config.cjs"),
],
content: ['./src/**/*.{html,js,svelte,ts}'],
} satisfies Config; tailwind-config-viewer/src/components/Canvas/Canvas.vue Lines 120 to 126 in bc9a737
This |
Hi @rogden, I also see the default config and I'm getting the following error
|
Ok I'm seeing default config as well. Didn't realize it since I use the default config for testing during local dev. Looking into it. @stijns96 Are you on mac or windows? |
Hi @rogden Forgot to mention, but I'm on windows! |
I fixed the default config appearing in v2.0.1 https://github.com/rogden/tailwind-config-viewer/releases/tag/v2.0.1. @stijns96 Ok thanks. Can you try 2.0.1? I doubt it will fix your issue but curious. I wonder if it has to do with the await import call I'm making now to support ESM: https://monosnap.com/file/RMLvjWD9RZMTL3mcNq80nnaTOp9dgN . Perhaps on windows it needs an alternative approach to the pathing? |
Hi @rogden , I'll try when I'm home! I already tried s couple of things and indeed, you have to adjust the path of the import. On windows you will get "C://" and the import only accept file and data. I'll try some other things for you as well qnd maybe you can think a bit along with me. Let you know! |
Hi @rogden, I tried some things out and found out that on Windows you have to add const { pathToFileURL } = require('url');
.action(args => {
require('../server')({
port: args.port,
tailwindConfigProvider: async () => {
const configPath = resolveConfigPath(program.config)
const configHref = pathToFileURL(configPath).href;
delete require.cache[configHref]
const config = await import(configHref)
return config.default || config
},
shouldOpen: args.open
}).start()
}) The above fixes my problem with the import, but from that point I get other errors. In my tailwind.config.mjs I'm importing the tailwind colors.
The error that I get now is:
|
@stijns96 Thanks for the update. I wonder if this is a common issue with relative dynamic import paths on WIndows? This post seems to hit on the issue: https://stackoverflow.com/questions/71432755/how-to-use-dynamic-import-from-a-dependency-in-node-js. Will need to look into it more. |
I'm using mac. package.json:
I get error: Console
Browser |
I'm also encountering this error. My situation:
tailwind.config.ts: import { Config } from "tailwindcss";
export default <Partial<Config>>{
content: [
"./index.html",
"./src/**/*.{js,ts,jsx,tsx}",
],
theme: {
extend: {},
},
plugins: [],
} I run
|
I am having the same issue as @casually-creative. Works great on MacOS. I am using a tailwind.config.js with module.exports Current node 20.10.0 |
Any update on the case? I'm using Vite and I'm also having the same error. |
@rogden Sorry for the ping. Do you have any news regarding this issue? I can't seem to get around it. Very unfortunate as I wanted to have a tailwind config dashboard while developing my app. There doesn't seem to be any worthwile alternatives out there. |
Hey all. Thanks for the updates. I haven't had time to look into this. I will take a look today and try @stijns96 's fix. @stijns96 Do you have any idea why it couldn't find the tailwindcss/colors import? Does the path line up in that error with your file system?
|
I published 2.0.3 (https://github.com/rogden/tailwind-config-viewer/releases/tag/v2.0.3) that should resolve the Windows issue. Please test and let me know. |
@stijns96 When using 2.0.3, you will need to add the .js extension to your tailwind/colors import statement: |
Nice! I'll try it out this week! 🦾 |
Hello! Using the default action (serve), it works correctly on Windows, but the same problem occurs when using |
@Nxtivision Thanks for the report. I'll get a fix in tonight. I know the issue (forgot to make the same update to export that fixed serve :) ). |
Hi there, This works! Haven't tested it on windows tho. |
@rogden I installed 2.0.3 and the issue is fixed. Thank you! However when I have my tailwind config file as a typescript file
|
Fixed in 2.0.4 (https://github.com/rogden/tailwind-config-viewer/releases/tag/v2.0.4) |
Can you add support for ES Modules? I am using Vite and it is not loading due to require(). Thanks
The text was updated successfully, but these errors were encountered: