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

fix: load vue-template-compiler with nuxt.resolver.requireModule #1327

Merged
merged 2 commits into from Oct 24, 2021

Conversation

kazupon
Copy link
Collaborator

@kazupon kazupon commented Oct 23, 2021

#297 has occurred in my environment too
https://github.com/kazupon/nuxt-i18n-next

There is comment at #297,
I've fixed with using this.nuxt.resolver.requireModule.

package.json Outdated Show resolved Hide resolved
src/core/hooks.js Outdated Show resolved Hide resolved
@kazupon
Copy link
Collaborator Author

kazupon commented Oct 24, 2021

I have just fixed the part pointed out in your review comments
5f63ca6

@kazupon
Copy link
Collaborator Author

kazupon commented Oct 24, 2021

I'm very sorry for the lack of explanation.

Because `Cannot find module 'vue-template-compiler’ error occurs in cases other than build time, like the below issue.
nuxt/vercel-builder#42

I am trying the verify & PoC of Nuxt Bridge / Nuxt3 support using @nuxtjs/i18n now in the repo here:
https://github.com/kazupon/nuxt-i18n-next

@nuxt/kit has an API to install existing modules made with Nuxt2.
Here is the code that uses the API:

https://github.com/kazupon/nuxt-i18n-next/blob/3cc2b3673b413b42eda4de477177755b0e9f696f/packages/nuxt-i18n/src/module.ts#L31

When I try to run the new module, which uses this existing @nuxtjs/i18n and is made with nuxt/kit, in the nuxt3 project, I get the following error:

 ERROR  Cannot find module 'vue-template-compiler'                                                                                                                         01:37:16
Require stack:
- /path/to/nuxt-i18n-next/node_modules/@nuxtjs/i18n/src/helpers/components.js

  Require stack:
  - /path/to/nuxt-i18n-next/node_modules/@nuxtjs/i18n/src/helpers/components.js
  at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
  at Function.resolve (node:internal/modules/cjs/helpers:108:19)
  at p (/path/to/nuxt-i18n-next/node_modules/jiti/dist/jiti.js:1:52925)
  at g (/path/to/nuxt-i18n-next/node_modules/jiti/dist/jiti.js:1:54200)
  at /path/to/nuxt-i18n-next/node_modules/@nuxtjs/i18n/src/helpers/components.js:6:28
  at g (/path/to/nuxt-i18n-next/node_modules/jiti/dist/jiti.js:1:55111)
  at /path/to/nuxt-i18n-next/node_modules/@nuxtjs/i18n/src/helpers/routes.js:2:19
  at g (/path/to/nuxt-i18n-next/node_modules/jiti/dist/jiti.js:1:55111)
  at Object.<anonymous> (/path/to/nuxt-i18n-next/node_modules/@nuxtjs/i18n/src/core/hooks.js:25:28)
  at Object.extendRoutes (/path/to/nuxt-i18n-next/node_modules/@nuxt/kit/dist/index.mjs:814:17)
  at Builder.resolveRoutes (node_modules/@nuxt/builder/dist/builder.js:546:56)
  at async Promise.all (index 1)
  at async Builder.generateRoutesAndFiles (node_modules/@nuxt/builder/dist/builder.js:375:5)
  at async Builder.build (node_modules/@nuxt/builder/dist/builder.js:319:5)
  at async Object._buildDev (node_modules/@nuxt/cli/dist/cli-dev.js:107:5)
  at async Object.startDev (node_modules/@nuxt/cli/dist/cli-dev.js:65:7)

From this stack trace, if you install nuxt/kit with API installModule, it will execute the build process of @nuxtjs/i18n.

This is outside the topic of this issue.

To be honest, I'm not sure if it's best practice to use installModule in nuxt/kit to load an existing Nuxt module.
In fact, from reading this code in nuxt/kit, it seems to support compatibility with existing Nuxt modules.

In fact, installModule is used here

I think @pi0 would know if I'm right about it.

In any case, from previous issues, I think the same problem may occur in the future.
So, I think this issue should be fixed.

@pi0
Copy link

pi0 commented Oct 24, 2021

Hi! I have no knowledge of nuxt-i18n-next usage but seems a valid fix as this module has no explicit dependency on vue-template-compoiler, resolveModule uses a better search path that includes @nuxt packages that actually require it.

Using installModule` should be fine btw :)

@rchl rchl merged commit c5a3ca8 into nuxt-modules:main Oct 24, 2021
@rchl
Copy link
Collaborator

rchl commented Oct 24, 2021

Thanks

@kazupon kazupon deleted the fix/vue-tempalte-compiler-dep branch October 25, 2021 00:43
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

Successfully merging this pull request may close these issues.

None yet

3 participants