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

Quasar (Vite) | Error on startup: "Hook is not a function" #3357

Closed
4 tasks done
xSavior-of-God opened this issue Nov 20, 2023 · 2 comments
Closed
4 tasks done

Quasar (Vite) | Error on startup: "Hook is not a function" #3357

xSavior-of-God opened this issue Nov 20, 2023 · 2 comments

Comments

@xSavior-of-God
Copy link

UnoCSS version

v0.57.6

Describe the bug

Hello,
I have a problem with Unocss and Quasar, the Unocss plugins gives me and error related to the hook...

When starting the dev server ('quasar dev') this error appears.

image

After various tests I discovered that it's fault of the UnoCSS plugin which returns "undefined" instead of the "transform()" function, the error is caused by the "resolveHtmlTransforms" function that require the function "transform" inside the "transformIndexHtml" if is an object or just transformIndexHtml as function.

...node_modules/vite/dist/node/chunks/dep-6e2fe41e.js:36775:27

function resolveHtmlTransforms(plugins) {
    const preHooks = [];
    const postHooks = [];
    for (const plugin of plugins) {
        const hook = plugin.transformIndexHtml;
        if (hook) {
            if (typeof hook === 'function') {
                postHooks.push(hook);
            }
            else if (hook.enforce === 'pre') {
                preHooks.push(hook.transform);
            }
            else {
                postHooks.push(hook.transform);
            }
        }
    }
    return [preHooks, postHooks];
}
async function applyHtmlTransforms(html, hooks, ctx) {
    const headTags = [];
    const headPrependTags = [];
    const bodyTags = [];
    const bodyPrependTags = [];
    for (const hook of hooks) {
        const res = await hook(html, ctx);
        if (!res) {
            continue;
        }

Currently I did a work around for my project... and it works now, but this for sure is not the correct way to fix this bug/error and idk how many other unknown issues it can cause...

...quasar.config.js

      // extendViteConf (viteConf) {},
      extendViteConf(config) {
        let _UnoCSS = UnoCSS.default({
          onlyGlobal: true,
          presets: [
            presetUno(),
            presetAttributify(),
            presetIcons({
              scale: 1.2,
              cdn: 'https://esm.sh/',
            }),
          ],
        });
        for(let plugin of _UnoCSS) {
          if(plugin && plugin.transformIndexHtml) {
            plugin.transformIndexHtml.enforce = 'pre';
            plugin.transformIndexHtml.transform = function(){};
          }
        }
        config.plugins.push(..._UnoCSS);
      },

Reproduction

To reproduce the problem, just run the official UnoCSS with Quasar example on GitHub via Stackblitz.

Open in StackBlitz

System Info

NodeJS: v18.18.0
NPM: v9.4.2
System: Windows 10/11
Browser: Edge & Chrome
Framework: Quasar CLI (with Vite)
Quasar: v2.14.0
Vue: v3.3.8

Validations

@Yooye
Copy link

Yooye commented Nov 21, 2023

npm install -D unocss@0.56.1
我也遇到了这个问题,我用vite3搭建的项目,使用上面的命令降版本后,可以恢复正常
下面是我项目依赖的版本信息:

{
  "name": "vuets-admin-2304",
  "private": true,
  "version": "0.0.0",
  "type": "module",
  "scripts": {
    "dev": "vite",
    "build": "vue-tsc && vite build",
    "preview": "vite preview"
  },
  "dependencies": {
    "element-plus": "^2.4.2",
    "normalize.css": "^8.0.1",
    "reset-css": "^5.0.2",
    "vue": "^3.2.41"
  },
  "devDependencies": {
    "@vitejs/plugin-vue": "^3.2.0",
    "typescript": "^4.6.4",
    "unocss": "^0.56.1",
    "unplugin-auto-import": "^0.16.7",
    "unplugin-vue-components": "^0.25.2",
    "vite": "^3.2.3",
    "vue-tsc": "^1.0.9"
  }
}

@xSavior-of-God
Copy link
Author

npm install -D unocss@0.56.1 我也遇到了这个问题,我用vite3搭建的项目,使用上面的命令降版本后,可以恢复正常 下面是我项目依赖的版本信息:

{
  "name": "vuets-admin-2304",
  "private": true,
  "version": "0.0.0",
  "type": "module",
  "scripts": {
    "dev": "vite",
    "build": "vue-tsc && vite build",
    "preview": "vite preview"
  },
  "dependencies": {
    "element-plus": "^2.4.2",
    "normalize.css": "^8.0.1",
    "reset-css": "^5.0.2",
    "vue": "^3.2.41"
  },
  "devDependencies": {
    "@vitejs/plugin-vue": "^3.2.0",
    "typescript": "^4.6.4",
    "unocss": "^0.56.1",
    "unplugin-auto-import": "^0.16.7",
    "unplugin-vue-components": "^0.25.2",
    "vite": "^3.2.3",
    "vue-tsc": "^1.0.9"
  }
}

Thanks for the comment... the problem starts from version 0.57.2, so at the moment the latest working version with (Quasar) Vite is 0.57.1

npm install -D unocss@0.57.1

@antfu antfu closed this as completed in 49b3451 Nov 21, 2023
renovate bot added a commit to yjl9903/AnimeSpace that referenced this issue Nov 21, 2023
[![Mend Renovate logo
banner](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [@unocss/reset](https://togithub.com/unocss/unocss) | [`^0.57.6` ->
`^0.57.7`](https://renovatebot.com/diffs/npm/@unocss%2freset/0.57.6/0.57.7)
|
[![age](https://developer.mend.io/api/mc/badges/age/npm/@unocss%2freset/0.57.7?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/@unocss%2freset/0.57.7?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/@unocss%2freset/0.57.6/0.57.7?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/@unocss%2freset/0.57.6/0.57.7?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
| [unocss](https://togithub.com/unocss/unocss) | [`^0.57.6` ->
`^0.57.7`](https://renovatebot.com/diffs/npm/unocss/0.57.6/0.57.7) |
[![age](https://developer.mend.io/api/mc/badges/age/npm/unocss/0.57.7?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/unocss/0.57.7?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/unocss/0.57.6/0.57.7?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/unocss/0.57.6/0.57.7?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|

---

### Release Notes

<details>
<summary>unocss/unocss (@&#8203;unocss/reset)</summary>

### [`v0.57.7`](https://togithub.com/unocss/unocss/releases/tag/v0.57.7)

[Compare
Source](https://togithub.com/unocss/unocss/compare/v0.57.6...v0.57.7)

#####    🚀 Features

- **core**: Preset support blocklist  -  by
[@&#8203;chizukicn](https://togithub.com/chizukicn) in
[unocss/unocss#3363
[<samp>(1ce68)</samp>](https://togithub.com/unocss/unocss/commit/1ce68380)

#####    🐞 Bug Fixes

- **vite**: Compatible with legacy Vite on `transformIndexHtml`, fix
[#&#8203;3357](https://togithub.com/unocss/unocss/issues/3357)  -  by
[@&#8203;antfu](https://togithub.com/antfu) in
[unocss/unocss#3357
[<samp>(49b34)</samp>](https://togithub.com/unocss/unocss/commit/49b34510)

#####     [View changes on
GitHub](https://togithub.com/unocss/unocss/compare/v0.57.6...v0.57.7)

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about these
updates again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://developer.mend.io/github/yjl9903/AnimeSpace).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy41OS44IiwidXBkYXRlZEluVmVyIjoiMzcuNTkuOCIsInRhcmdldEJyYW5jaCI6Im1haW4ifQ==-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants