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.

Cannot import single component with Nuxt

See original GitHub issue

Operating system: Ubuntu Browser and version: Node v8.9.4 Bootstrap-Vue: 2.0.0-rc2 Nuxt: 1.4.0 Repo reproducing the issue: https://github.com/Okazari/bootstrap-vue-nuxt/tree/master/bootstrap-vue-nuxt

Hey, i’m runing into an issue when using Bootstrap-vue along with Nuxt : As some of my page are only using few components, i want to import them directly instead of importing the whole vue module to profit from nuxt automatic page chunks.

But when i do this in my component

import bButton from 'bootstrap-vue/es/components/button/button';

export default {
  components: {
    bButton,
  }
}

It works fine on the browser (if there is only hot-reload, or if i navigate to the concerned page through the browser) but i run into the following error when it run on the server (by refreshing the page that use the component) :

import { mergeData } from 'vue-functional-data-merge';
^^^^^^

SyntaxError: Unexpected token import

Providing a built file for each component would solve the issue but this is not the best idea (since importing multiple built components would duplicate common javascript). Any workaround ? Should i totally forgot about doing such optimization (i have the same issue with importing a component as a module btw) ?

Thanks in advance 😃 !

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
rafaelmagalhaescommented, Oct 24, 2018

has this been resolved having same problem how can i fix it ?

1reaction
saintechcommented, Nov 25, 2018

This worked for me:

// nuxt.config.js
module.exports = {
  mode: 'universal',
  '...',
  build: {
    '...',
    transpile: ['bootstrap-vue']
  }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Nuxt not automatically importing components from nested ...
In my nuxt app, components in nested directories are not automatically importing as expected. For some of my components i have something ...
Read more >
Importing and Using Components in Nuxt 3 - Server Side Up
When migrating from Nuxt 2 to Nuxt 3, components are now imported and used through auto imports instead of explicit importing.
Read more >
Plugins directory - Nuxt
Another way to use axios without installing the module is by importing axios direct in the <script> tag. pages/index.vue <script> import axios from...
Read more >
How to resolve Cannot import module '@nuxt/builder'?-Vue.js
[Solved]-How to resolve Cannot import module '@nuxt/builder'?-Vue.js · score:0. For those in the same boat as I was, think critically. If something feels...
Read more >
Getting Started - BootstrapVue
Note that when importing individual components, any component aliases will not be available. Note: Optimal tree shaking only works when your Nuxt.js app...
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