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

[Bug Report][3.0.0-alpha.9][SSR] Cannot find module 'vuetify/lib/components' #13936

Closed
brillout opened this issue Jul 16, 2021 · 16 comments
Closed
Assignees
Milestone

Comments

@brillout
Copy link

Environment

Vuetify Version: 3.0.0-alpha.9
Vue Version: 3.0.11
Browsers: Chrome 91.0.4472.102
OS: Chromium OS 13904.55.0

Steps to reproduce

  1. yarn install
  2. yarn dev
  3. Go to https://localhost:3000

Expected Behavior

No error is thrown.

Actual Behavior

Error is thrown:

Error: Cannot find module 'vuetify/lib/components' from '/home/brillout/tmp/vuetify3-ssr/pages/_default'
    at Function.resolveSync [as sync] (/home/brillout/tmp/vuetify3-ssr/node_modules/resolve/lib/sync.js:107:15)
    at resolveFrom$3 (/home/brillout/tmp/vuetify3-ssr/node_modules/vite/dist/node/chunks/dep-11db14da.js:4076:29)
    at resolve (/home/brillout/tmp/vuetify3-ssr/node_modules/vite/dist/node/chunks/dep-11db14da.js:73358:22)
    at nodeRequire (/home/brillout/tmp/vuetify3-ssr/node_modules/vite/dist/node/chunks/dep-11db14da.js:73337:25)
    at ssrImport (/home/brillout/tmp/vuetify3-ssr/node_modules/vite/dist/node/chunks/dep-11db14da.js:73290:20)
    at eval (/pages/_default/vuetify.js:9:31)
    at instantiateModule (/home/brillout/tmp/vuetify3-ssr/node_modules/vite/dist/node/chunks/dep-11db14da.js:73323:166)

Reproduction Link

https://github.com/brillout/vuetify3-ssr

Other comments

Hi, is vuetify supposed to work with SSR and Vite?

Trying to use Vuetify + Vite + SSR leads to an error where the npm package resolve cannot find vuetify/lib/components.

@ghost ghost added the S: triage label Jul 16, 2021
@pg-ahenry
Copy link
Contributor

pg-ahenry commented Jul 16, 2021

same thing with vite-ssg, looks like it compiles
import * as components from 'vuetify/lib/components' into require('vuetify/lib/components') which causes that error (same with directives)

@frandiox
Copy link

There's an example here although I don't see any component import: https://github.com/vuetifyjs/vuetify/tree/next/packages/vuetify/dev

According to a conversation on Discord, I think @KaelWD got import * as components from "vuetify/lib/components" working.

@KaelWD
Copy link
Member

KaelWD commented Jul 19, 2021

That was for the dev environment which imports from src. To get prod working with vite you might have to change the import to vuetify/lib/components/index.mjs. I'll see if adding package exports makes it work without the extension.

@KaelWD KaelWD self-assigned this Jul 19, 2021
@brillout
Copy link
Author

That was for the dev environment which imports from src. To get prod working with vite you might have to change the import to vuetify/lib/components/index.mjs. I'll see if adding package exports makes it work without the extension.

cc @cprcrack

@KaelWD
Copy link
Member

KaelWD commented Jul 19, 2021

You could also try adding vuetify to ssr.noExternal

@pg-ahenry
Copy link
Contributor

Can confirm changing to vuetify/lib/components/index.mjs works (no error with vite-ssg)

@brillout
Copy link
Author

You could also try adding vuetify to ssr.noExternal

Why would I want to do this? I don't see why Vite should transpile Vuetify? (Thanks for your lovely work btw.)

@brillout
Copy link
Author

Adding /index.mjs resolves the error but I now get:

5:56:15 PM [vite] Error when evaluating SSR module /node_modules/vuetify/lib/components/VList/VListItemTitle.mjs:
TypeError: Cannot read property 'defineComponent' of null
    at Module.createSimpleFunctional (../../src/util/createSimpleFunctional.ts:9:24)
    at ../../../src/components/VList/VListItemTitle.ts:3:37
    at instantiateModule (/home/romuuu/tmp/vite-plugin-ssr-vuetify/node_modules/vite/dist/node/chunks/dep-11db14da.js:73323:166)

Not only for VListItemTitle but also for many(/all?) components.

@brillout
Copy link
Author

I updated the reproduction https://github.com/brillout/vuetify3-ssr

@brillout
Copy link
Author

Adding /index.mjs resolves the error but I now get:

5:56:15 PM [vite] Error when evaluating SSR module /node_modules/vuetify/lib/components/VList/VListItemTitle.mjs:
TypeError: Cannot read property 'defineComponent' of null
    at Module.createSimpleFunctional (../../src/util/createSimpleFunctional.ts:9:24)
    at ../../../src/components/VList/VListItemTitle.ts:3:37
    at instantiateModule (/home/romuuu/tmp/vite-plugin-ssr-vuetify/node_modules/vite/dist/node/chunks/dep-11db14da.js:73323:166)

Not only for VListItemTitle but also for many(/all?) components.

Adding vuetify to ssr.noExternal doesn't help.

@brillout
Copy link
Author

I also get:

Circular dependency: /home/romuuu/tmp/vite-plugin-ssr-vuetify/node_modules/vite-plugin-ssr/dist/esm/page-files/pageFiles.node.js -> /pages/_default/_default.page.server.js -> /pages/_default/app.js -> /pages/_default/vuetify.js -> /node_modules/vuetify/lib/entry.mjs -> /node_modules/vuetify/lib/framework.mjs -> /node_modules/vuetify/lib/util/index.mjs -> /node_modules/vuetify/lib/util/createSimpleFunctional.mjs -> /node_modules/vuetify/lib/util/index.mjs
Circular dependency: /home/romuuu/tmp/vite-plugin-ssr-vuetify/node_modules/vite-plugin-ssr/dist/esm/page-files/pageFiles.node.js -> /pages/_default/_default.page.server.js -> /pages/_default/app.js -> /pages/_default/vuetify.js -> /node_modules/vuetify/lib/components/index.mjs -> /node_modules/vuetify/lib/components/VTimeline/index.mjs -> /node_modules/vuetify/lib/components/VTimeline/VTimelineItem.mjs -> /node_modules/vuetify/lib/components/VTimeline/VTimelineDivider.mjs -> /node_modules/vuetify/lib/components/index.mjs

@KaelWD
Copy link
Member

KaelWD commented Jul 19, 2021

Looks like we get the same thing in our SSR environment too. This was probably broken by 3520db1

@remohammadi
Copy link

I am getting the same error when I try to setup vuetify and pass it to wrapper in my unit test code. But, with yarn serve, I do not have such problem. The same code works perfectly. I should note that adding index.mjs didn't help me. So, maybe I should open a new issue. Should I? 😁

vuetify version: 3.0.0-alpha.10
jest version: 26.6.3

// StatusBtn.spec.ts
import { shallowMount } from "@vue/test-utils";
import { createI18n } from "vue-i18n";
import { store, key } from "@/store";
import { createVuetify } from "vuetify";
import * as components from "vuetify/lib/components";
import * as directives from "vuetify/lib/directives";
import StatusBtn from "@/components/commons/StatusBtn.vue";

describe("StatusBtn.vue", () => {
  it("report disconnected status with the initial state", () => {
    const i18n = createI18n({ locale: "en" });
    const vuetify = createVuetify({components, directives});
    const wrapper = shallowMount(StatusBtn, {
      global: {
        plugins: [i18n, vuetify, [store, key]],
      },
    });
    expect(wrapper.text()).toMatch("status: disconnected");
  });
});

I get:

  ● Test suite failed to run

    Cannot find module 'vuetify/lib/components' from 'tests/unit/StatusBtn.spec.ts'

When /index.mjs was added:

  ● Test suite failed to run

    tests/unit/StatusBtn.spec.ts:5:29 - error TS2307: Cannot find module 'vuetify/lib/components/index.mjs' or its corresponding type declarations.

@jamesladd
Copy link

I have this working for me on the client side.

page/_default/vuetify.js ->

`import '@mdi/font/css/materialdesignicons.css'
import 'vuetify/lib/styles/main.sass'
import { createVuetify } from 'vuetify'
import * as components from 'vuetify/lib/components/index.mjs'
import * as directives from 'vuetify/lib/directives/index.mjs'

export default createVuetify({ components, directives })
`

vite.config.js -> ( this is a little specific to my needs - ie: runtimeCompiler and vue alias.

export default { runtimerCompiler: true, plugins: [vue(), ssr()], define: { 'process.env': {} }, ssr: { noExternal: ['vuetify'] }, resolve: { alias: { vue: 'vue/dist/vue.esm-bundler.js', }, },

@vue/cli 4.5.13
"vuetify": "^3.0.0-alpha.10",
"vite-plugin-ssr": "^0.2.11",
"vue": "^3.0.11",

The fact that a browser based button is shown then styled is a little worry but no related.

I'll try the above with a vanilla vite-ssr-plugin project and let you know.

@KaelWD
Copy link
Member

KaelWD commented Sep 4, 2021

Alpha 11 now uses package exports, so you should be able to import from vuetify/components without an extension.

@KaelWD KaelWD closed this as completed Sep 4, 2021
@brillout
Copy link
Author

brillout commented Sep 6, 2021

@KaelWD I can confirm.

But now I get:

11:44:06 AM [vite] Error when evaluating SSR module /renderer/vuetify.js:
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /home/romuuu/tmp/vite-plugin-ssr-vuetify/node_modules/vuetify/lib/framework.mjs

Repro: https://github.com/brillout/vite-plugin-ssr-vuetify/tree/updated-deps.

Note that the repro does use ESM (package.json#type === 'module').

It's a Vite problem and there is a proposal to make Vite better support ESM dependencies. @KaelWD I can keep you in the loop, if you want.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants