nuxt-modules / tailwindcss

Tailwind CSS module for Nuxt
https://tailwindcss.nuxtjs.org
MIT License
1.68k stars 183 forks source link

Using Resolver in Tailwind.config.js breaks in 6.8.0 #701

Closed JohnCampionJr closed 1 year ago

JohnCampionJr commented 1 year ago

Version

@nuxtjs/tailwindcss: 6.8.0 nuxt: 3.5.1

Reproduction Link

Steps to reproduce

I am using a resolver in tailwind.config.js to find a json file:

import { createResolver } from '@nuxt/kit'

const icons = require('@jcamp/tailwindcss-plugin-icons')

const { resolve } = createResolver(import.meta.url)

/** @type {import('tailwindcss').Config} */
module.exports = {
  plugins: [
    icons(
      { scale: 1.1,
        jsonCollections: {
          'fa-duotone': resolve('./assets/fa-duotone.json')
        }
      }
    ),
  ],
}

This works fine up v6.8.0. In 6.8.0 I get the following error:

 [nuxt:tailwindcss] Failed to load Tailwind config at: `./../nuxt-base/tailwind.config.js` Cannot use 'import.meta' outside a module
    const { resolve } = _kit.createResolver.call(void 0, import.meta.url)
    ^^^^

What is Expected?

Same behavior as earlier versions

What is actually happening?

Error above

ineshbose commented 1 year ago

Ooh that looks quite fragile as you're mixing CJS with EMS and kit utilities in non-module context. This can be re-designed as a module.. (can look into it in a few hours)

JohnCampionJr commented 1 year ago

Thank you; I've been trying to resolve this by converting to TS but even this still breaks

import type { Config } from 'tailwindcss'
import { createResolver } from '@nuxt/kit'

import icons from '@jcamp/tailwindcss-plugin-icons'

const { resolve } = createResolver(import.meta.url)

export default {
  plugins: [
    icons.createPluginIcons({
      scale: 1.1,
      jsonCollections: {
        'fa-duotone': resolve('./assets/fa-duotone.json'),
      },
    }),
  ]
} satisfies Config
JohnCampionJr commented 1 year ago

In case anyone else has a similar issue, I moved my tailwind config into the nuxt.config.ts to use the resolver.

Still not sure why it broke between these releases.