nuxt-icons icon indicating copy to clipboard operation
nuxt-icons copied to clipboard

ERROR [unhandledRejection] nuxtCtx.tryUse is not a function

Open nyxb opened this issue 3 years ago • 3 comments

idk

nyxb avatar Aug 07 '22 13:08 nyxb

I had the same problem

xiaogangLin avatar Aug 10 '22 11:08 xiaogangLin

@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?

gitFoxCode avatar Aug 11 '22 10:08 gitFoxCode

@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.

xiaogangLin avatar Aug 12 '22 02:08 xiaogangLin

@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

gitFoxCode avatar Nov 17 '22 14:11 gitFoxCode