Skip to content
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

[BUG] Support tailwind.config.ts #228

Closed
itsmingjie opened this issue Mar 28, 2023 · 7 comments · Fixed by #242
Closed

[BUG] Support tailwind.config.ts #228

itsmingjie opened this issue Mar 28, 2023 · 7 comments · Fixed by #242
Labels
bug Something isn't working

Comments

@itsmingjie
Copy link

itsmingjie commented Mar 28, 2023

Describe the bug
Tailwind release v3.3 today introduced support for ESM and TypeScript config files. It currently does not look like the ESLint plugin supports configuration files written in tailwind.config.ts.

To Reproduce

  1. Follow the demo instructions in the v3.3 release blog post and set up a TypeScript configuration.
  2. Run eslint
  3. The configuration file is not loaded in, causing false positives.

Expected behavior
Config files written with tailwind.config.ts should be supported.

Environment (please complete the following information):

  • Tailwind v3.3
  • ESLint v8.36.0
  • Plugin: v3.10.1

Additional context
This may be a duplicate of #156, but it is introduced with a different context. Escalated it to bug because there is now official support for config files written in TypeScript.

Related upstream PR
tailwindlabs/tailwindcss#10785

@itsmingjie itsmingjie added the bug Something isn't working label Mar 28, 2023
@taep96
Copy link

taep96 commented Mar 28, 2023

Related: #190
Relevant code: lib/util/customConfig.js

I think looking up all js/ts formats is the best solution: tailwind.config.{js,mjs,cjs,ts,mts,cts}

The old workaround unfortunately doesn't work for ESM/TS files.

@itsmingjie
Copy link
Author

itsmingjie commented Mar 28, 2023

I think TypeScript needs to be compiled down before it can be parsed directly by the plugin, it's not working for me even after specifying .ts. I could be wrong though.

@taep96
Copy link

taep96 commented Mar 28, 2023

I was editing my comment when you said that 😅

@pm0u
Copy link

pm0u commented Mar 31, 2023

I managed to get this working following this (somewhat ridiculous) suggestion from before TS support existed for Tailwind.

yarn add -D @swc-node/register @swc/core
// tailwind-config.js
const { register } = require("@swc-node/register/register")
const {
  readDefaultTsConfig,
} = require("@swc-node/register/read-default-tsconfig")
const path = require("path")
register(readDefaultTsConfig(path.join(__dirname, "tsconfig.json")))
module.exports = require("./tailwind.config").default
// tailwind.config.ts

export default {
  plugins: [],
  theme: {
    extend: {},
  },
  /** ... */
} 
// .eslintrc.js

module.exports = {
  extends: [
    "plugin/tailwindcss:recommended"
  ],
  settings: {
    tailwindcss: {
      config: "./tailwind-config.js"
    }
  }
}

I opted to make the JS file a non-autodetectable name since some things might pick it up by default otherwise. Mainly storybook.

Edit: I'm actually not sure the above works. It seems to work in VSCode, but the CLI doesn't seem to work properly.

edit again: Ok, they are in fact both working properly. Changing branches and things, i ran into some weird issues with errors showing up in VSCode but not the CLI. it seems like removing node_modules fixes the issue though. I'm not really sure why.

@tonyxiao
Copy link

tonyxiao commented May 1, 2023

Why not use jiti which is the strategy used by tailwind itself?

@pm0u
Copy link

pm0u commented May 2, 2023

I hadn't heard of jiti - i changed my implementation to use it because I was running into issues with deploying serverless functions on Vercel, they were pulling in SWC. really an issue with their dependency resolution, but since jiti is smaller it solved our issue so thanks for mentioning that package @tonyxiao

@quesabe
Copy link
Contributor

quesabe commented May 3, 2023

Seems like a possible solution is to use loadConfig from tailwindcss.

In addition within the rules instead of using default value for config (defined in the rule context as a string) the resolveDefaultConfigPath should be used to look for all possible extensions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants