question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

dynamic component import not imported in build

See original GitHub issue

Do NOT ignore this template or your issue will have a very high chance to be closed without comment.

Describe the bug

When i import dynamically a component, everything work on dev, but the component doesn’t exist on build.

I import component with this function

const importPage = path => () => import(`./pages/${path}.vue`)

When i build, the CSS is not created. (because the css is only in this page)

But when i manually import the component import Home from '/~/pages/home/Home.vue' The CSS is here.

System Info

  • required vite version: v1.0.0-rc.3
  • required Operating System: Linux
  • required Node version: v12.11.1
  • Optional:
    • npm/yarn version: 1.12.3
    • Installed vue version (from yarn.lock or package-lock.json) 3.0.0-rc.4
    • Installed @vue/compiler-sfc version 3.0.0-rc.4

Logs (Optional if provided reproduction)

Without import Home from '/~/pages/home/Home.vue' Screen Shot 2020-07-25 at 4 18 05 PM

With import Home from '/~/pages/home/Home.vue' Screen Shot 2020-07-25 at 4 19 49 PM

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
underfincommented, Jul 28, 2020

This is expected behavior.For the css of dynamic module will be packaged into js.

0reactions
simultsopcommented, Feb 4, 2021

This works with vue-cli (webpack) but not in vite, you could also iterate an array of filenames and require each of them before build on vue-cli. It was very helpful for code splitting.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Dynamic import of component fails - vue.js - Stack Overflow
Depending on what's happening in your file, you sometimes cannot dynamically import a component. Let's say if you need some values right ...
Read more >
Dynamically Importing Components with React.lazy
Not all static imports are immediately needed, and unnecessary imports can be costly. With React.lazy, you can dynamically import components ...
Read more >
[SOLVED] - Dynamic import not working - help - Meteor forums
Hey there! I'm trying to implement dynamic loading to split the code per page to minimise the main bundle size cause the app...
Read more >
Advanced Features: Dynamic Import - Next.js
Dynamically import JavaScript modules and React Components and split your code ... By using next/dynamic , the header component will not be included...
Read more >
Features | Vite
Native ES imports do not support bare module imports like the following: ... Vite provides first-party HMR integrations for Vue Single File Components...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found