gitFoxCode / nuxt-icons

Module for Nuxt allowing pleasant use of svg icons
188 stars 23 forks source link

ERROR [unhandledRejection] nuxtCtx.tryUse is not a function #7

Closed nyxb closed 1 year ago

nyxb commented 1 year ago

idk

xiaogangLin commented 1 year ago

I had the same problem

gitFoxCode commented 1 year ago

@VidarDev @xiaogangLin Could you write when this error occurs or possibly create some quick environment so I can test this error and fix it as soon as possible?

xiaogangLin commented 1 year ago

@gitFoxCode Hi. when this error occurs I got the error log infos:

ERROR  Cannot start nuxt:  nuxtCtx.tryUse is not a function
  at useNuxt (?????/node_modules/nuxt-icons/node_modules/@nuxt/kit/dist/index.mjs:47:28)
  at addTemplate (?????/node_modules/nuxt-icons/node_modules/@nuxt/kit/dist/index.mjs:58:16)
  at setup (?????/node_modules/nuxt-icons/dist/module.mjs:18:5)
  at Object.normalizedModule (?????/node_modules/nuxt-icons/node_modules/@nuxt/kit/dist/index.mjs:624:29)
  at async installModule (?????/node_modules/@nuxt/kit/dist/index.mjs:432:3)
  at async initNuxt (?????/node_modules/nuxt/dist/index.mjs:1423:7)
  at async load (?????/node_modules/nuxi/dist/chunks/dev.mjs:6750:9)
  at async Object.invoke (?????/node_modules/nuxi/dist/chunks/dev.mjs:6795:5)
  at async _main (?????/node_modules/nuxi/dist/cli.mjs:46:20)

ERROR  [unhandledRejection] nuxtCtx.tryUse is not a function
  at useNuxt (?????/node_modules/nuxt-icons/node_modules/@nuxt/kit/dist/index.mjs:47:28)
  at addComponentsDir (?????/node_modules/nuxt-icons/node_modules/@nuxt/kit/dist/index.mjs:805:16)
  at setup (?????/node_modules/nuxt-icons/dist/module.mjs:16:5)
  at async installModule (?????/node_modules/@nuxt/kit/dist/index.mjs:432:3)
  at async initNuxt (?????/node_modules/nuxt/dist/index.mjs:1423:7)

I used the error log infos to locate the wrong code snippet from line 45:

// ?????/node_modules/nuxt-icons/node_modules/@nuxt/kit/dist/index.mjs:47:28
const nuxtCtx = getContext("nuxt");
function useNuxt() {
  const instance = nuxtCtx.tryUse();
  // nuxtCtx.tryUse is not a function, try to solve: const instance = nuxtCtx.use();

  if (!instance) {
    throw new Error("Nuxt instance is unavailable!");
  }
  return instance;
}

I found nuxtCtx dosen't have property tryUse but have property use.I tried to make nuxtCtx.tryUse() modify to nuxtCtx.use() and there is no error. So I think it might be related to @nuxt/kit version.

gitFoxCode commented 1 year ago

@xiaogangLin Hey, the new version for the stable version nuxt 3.0.0 just came out, all such problems should no longer occur. If anything, please write a new issue