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

ESM packages without a "main" field is not detected/loaded correctly #17880

Closed
Wangijun opened this issue Mar 5, 2025 · 3 comments
Closed

ESM packages without a "main" field is not detected/loaded correctly #17880

Wangijun opened this issue Mar 5, 2025 · 3 comments
Labels
area/cli bug/2-confirmed We have reproduce the problem and confirmed that this is a bug. flavour/quasar-cli-vite kind/bug 🐞 Qv2 🔝 Quasar v2 issues

Comments

@Wangijun
Copy link

Wangijun commented Mar 5, 2025

What happened?

When integrating into Quasar using the Vite plugin according to Tailwind CSS v4,

build: {
  vitePlugins: [
    // both are perfectly equivalent:
    [ '<plugin-name>', { /* plugin options */ } ],
    [ '<plugin-name>', { /* plugin options */ }, { server: true, client: true } ]
  ]
}

The use ofsyntax does not work. Now I am using an import method, and the ugly looking code is what makes the Tailwind CSS v4 Vite plugin work, as shown below

import tailwindcss from '@tailwindcss/vite'

vitePlugins: [
        // ['@tailwindcss/vite', {}],
        // tailwindcss  here !!!
        [tailwindcss as unknown as string, {}],
      ],

What did you expect to happen?

I believe that regardless of which grammar is used, it should work properly

Reproduction URL

https://stackblitz.com/edit/quasarframework-stackblitz-templates-hbcyrpyp?file=quasar.config.js

How to reproduce?

Follow the Tailwind CSS Vite integration documentation and configure it using Quasar's Vite plugin configuration method, and it will appear

Flavour

Quasar CLI with Vite (@quasar/cli | @quasar/app-vite)

Areas

Quasar CLI Commands/Configuration (@quasar/cli | @quasar/app-webpack | @quasar/app-vite)

Platforms/Browsers

Chrome

Quasar info output

Relevant log output

Additional context

No response

@Wangijun Wangijun added kind/bug 🐞 Qv2 🔝 Quasar v2 issues labels Mar 5, 2025
@github-actions github-actions bot added area/cli bug/1-repro-available A reproduction is available and needs to be confirmed. flavour/quasar-cli-vite labels Mar 5, 2025
@yusufkandemir yusufkandemir changed the title The latest version of Quasar's integration with Tailwind CSS v4 is not effective ESM packages without a "main" field is not detected/loaded correctly Mar 5, 2025
@yusufkandemir yusufkandemir added bug/2-confirmed We have reproduce the problem and confirmed that this is a bug. and removed bug/1-repro-available A reproduction is available and needs to be confirmed. labels Mar 5, 2025
@yusufkandemir
Copy link
Member

We use require.resolve to resolve package paths, which we use to detect the presence of a package, or to load and use that package:
https://github.com/quasarframework/quasar/blob/dev/app-vite/lib/utils/get-package-path.js

But, const require = createRequire(import.meta.url) acts for CJS. So, if an ESM-only package only defines exports and not main, require.resolve will fail with [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined in .... This is the case with TailwindCSS, as can be seen in tailwindlabs/tailwindcss#13216, tailwindlabs/tailwindcss#16751, etc.

import.meta.resolve is a release candidate in Node v18, v20, and v22. It does not require --experimental-import-meta-resolve anymore. However, that flag enables a second parameter called parent, which is basically the equivalent of { paths: [ parent ] } for require.resolve, which we were utilizing.
https://nodejs.org/docs/latest-v18.x/api/esm.html#importmetaresolvespecifier

As another alternative, we could handle errors from require.resolve and then fall back to import.meta.resolve or some other method, if we can't simply replace it altogether.

Yet another alternative, which will probably be the best solution:

@rstoenescu I hope this information is enough to decide on which action to take.

@rstoenescu
Copy link
Member

rstoenescu commented Mar 5, 2025

Yes, I've been keeping an eye on the native Node.js import.meta.resolve for some time now.
Unfortunately, the flag is required if it's to be used with a second param (which we absolutely need), no matter the current Node.js versions (18 to even 23):

Image

@rstoenescu
Copy link
Member

Fix will be available in q/app-vite v2.1.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/cli bug/2-confirmed We have reproduce the problem and confirmed that this is a bug. flavour/quasar-cli-vite kind/bug 🐞 Qv2 🔝 Quasar v2 issues
Projects
None yet
Development

No branches or pull requests

3 participants