When incorporating Vue Design System into Nuxt, I encountered issues with the system.js export functionality, resulting in errors

Trying to integrate components into a Nuxt project by following the steps outlined here: https://github.com/viljamis/vue-design-system/wiki/getting-started#using-design-system-as-an-npm-module

Nuxt doesn't use a main.js file (it's plugin-based), so I created a "plugin" and imported the code as follows (this is recommended by Nuxt for other libraries too):

vue-design-system.js

import Vue from 'vue'
import system from 'fp-design-system'
import 'fp-design-system/dist/system/system.css'

Vue.use(system)

In my configuration, I have (other code in config removed):

nuxt.config.js

module.exports = {
  css: [
    { src: 'fp-design-system/dist/system/system.css', lang: 'css' }
  ],
  plugins: [
    { src: '~plugins/vue-design-system', ssr: true }
  ]
}

When running npm run dev in my theme, it builds but triggers a warning:

WARNING Compiled with 1 warnings warning in ./plugins/vue-design-system.js 7:8-14 "export 'default' (imported as 'system') was not found in 'fp-design-system'

The issue seems to be with the generated system.js regarding export (while running npm run build:system).

On my page, when trying to use a component from the design system, I encounter this error:

NuxtServerError Cannot find module 'fp-design-system/src/elements/TextStyle' from '/Users/paranoidandroid/Documents/websites/Nuxt-SSR'

If I hard refresh the page, another message pops up:

NuxtServerError render function or template not defined in component: anonymous

Any insights on what might be going wrong here? It would be great to resolve this issue.

Currently uncertain if it's an issue with Nuxt or Vue Design System. Leaning towards the latter because my Nuxt setup is pretty bare-bones...so it's unlikely something else causing this.

Thank you.

Repository on GitHub:

Here is the repo for my "theme," however, to make it work, you'll need to create a separate design system with the same name and follow the steps to utilize the design system as a local (file) NPM module.

https://github.com/michaelpumo/Nuxt-SSR

console.log of system (from the JS import statement)

https://i.sstatic.net/1OnY7.png

Answer №1

Regarding the initial error ("

'export' default (imported as 'system') was not found in 'fp-design-system'
"), it seems that the UMD built JS file from vue-design-system does not have a "default" export object. You can resolve this by importing it using:

import * as system from 'fp-design-system'

Instead of:

import system from 'fp-design-system'

An additional issue arises with the error "window is not defined", which is due to the UMD built JS relying on window being globally available, rather than the usual use of this (which represents window in a browser context). This makes the build incompatible with Server-Side Rendering (SSR).

You could try modifying the JS build by replacing the first instance of window with this, although there is no guarantee that it will still function correctly.

It is recommended to use this module exclusively for client-side rendering to avoid any further complications.

Answer №2

Vue appears to be searching for the ES6 pattern for importing modules, which is required for external JavaScript modules/files.

In ES6, it looks like this:

export default myModule

In ES5, it appeared as follows:

module.exports = myModule

I trust this information will be beneficial to you.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Add a button that allows users to input their information into an array, and then display the data from the array in a <div>

I'm new to the coding world, so please bear with me if I miss any unspoken rules. I welcome any feedback. Essentially, I have three text input fields: Name:, Age:, and Password:. If any of these fields are left empty, an error message will display. H ...

Having trouble with injecting string HTML into the head section in NextJS?

We have incorporated a NextJS page with a headless CMS platform. Within this content management system, I have included an option for the administrator to save custom code snippets to be inserted either in the head section or at the end of the body. In m ...

Creating variables with increasing names can be done by using a loop in the

I'm having trouble figuring out how to approach this issue. Currently, I have a variable set up to store an object: var myobject = new object(); Everything is working fine; the name of the variable is 'my object' and it contains a new obj ...

The password-protected HTML blog remains hidden until the correct entry is entered into the password box, causing

After successfully creating a password redirect page where entering the correct password redirects you to another URL (psswrdtest.tumblr.com with the password as correctpsswrd, redirecting to google.com*), I attempted to improve it by making the password p ...

What steps can I take to successfully utilize $index named variables in Angular?

There is a div element in my HTML file with the following code: <div ng-repeat="loss in Model.plDetails track by $index"> <div class="col-sm-2"> <div class="input-group"> <input type="text" class="form-cont ...

What is the best way to retrieve the identity or specifics of the item that was right-clicked within the context menu

My AngularJS populated table includes a link button. When I right-click on this button, I've created a specific context menu using jQuery that pops up. The issue arises when I try to retrieve the ID of the item I clicked on in the context menu (such a ...

Proceed with the execution of the script after a successful completion of the jQuery AJAX request

I am facing a challenge with my click function that needs to open a popup window once the ajax call is successful. I have tried different solutions like setting async: false, placing the popup in the ajax call (which got blocked by the browser), and using ...

Adding a Vue component from the public folder in Laravel 5.5: A guide

My blade file contains the following code snippet: <div id="appCropper"> <cropper-admin></cropper-admin> </div> Additionally, there is a JavaScript file with the following content: let Child = { template: '<div> ...

Exploring the global property using VueJs 3 and InertiaJs Script Setup

I am currently working on setting up my InertiaJs / VueJs 3 / Laravel application to easily emit and listen to events using an event bus. After some research, I found the mitt package. To use it as a global variable on the vue instance, I followed this ap ...

Enhance the output of an array by incorporating additional text into the values

I'm diving into the world of Apps Script and I have a task at hand - adding some text to each value in an array. However, the code I currently have simply moves those values to another column: function getData() { var sheet1 = SpreadsheetApp.getAct ...

Having trouble implementing types with typescript in Vue-toastification for vuejs 3

Having trouble incorporating vue-toast-notification into my vue 3 project. The issue seems to be with vue Augmenting Types. I've tried other solutions without success, encountering the following error: TS2339: Property '$toast' does not exis ...

React frontend unable to retrieve JSON data from Rails API

I have developed a backend Rails API and confirmed that the endpoint is being accessed by monitoring my server in the terminal. Additionally, I am able to view the response in Postman. However, I am facing an issue where the payload is not returned in my R ...

Increasing the padding at the top of the logo when scrolling down the page

When scrolling down the page, there seems to be extra padding above the logo that is throwing off the alignment with the rest of the site. I've been trying different solutions to correct this issue: //$('.navbar-brand').css({ 'padding- ...

Customize context menu events based on the exact section where the menu was activated

Concern: The context menu functions, but it retains click events if pulled up on multiple divs. Steps to Replicate: Right-click one section. Click outside the menu to close it (without choosing an option). Click another section and choose an option. Delet ...

Value preselected in the dropdown menu

I need to display the 'Choose option' as a disabled option in a drop down list that is generated from another page. page1.php <div class="col-md-4"> <select class="form-control" name="task" id="task" required> ...

Trouble persisting Vue JS form data to Django Rest database

I am currently working on a project involving Django, Django REST, and Vue JS. I have successfully managed to retrieve information from the API to the Vue JS frontend. However, I am facing an issue where data is not being posted to the Django database when ...

Extracting data from AJAX-based PHP value

One part of the HTML code I'm trying to extract information from looks like this: <div class="price">15</div> Another part of the form is: <select name="group_1" id="group_1" class="attribute_select" onchange="findCombination();getPr ...

The Epub text box feature is malfunctioning

I have a quiz task in an epub format where users need to enter their answers in a text box after reading the question. However, I am facing an issue where the text box does not display the keyboard for typing the answer. Is there a solution using javascr ...

Discovering the process of previewing a video upload using react-player

Currently, I have an input that allows users to upload video files of type File. In my application, there is also a react-player component that requires a URL prop, which can be either an array or MediaStream according to its documentation. After doing som ...

The latest iteration of three.js appears to disrupt how light is reflected on meshes

After upgrading from three.js version r110 to r124 for the new features, I noticed a significant change in the way my meshes reflect light. Suddenly, everything looks different and it's quite disappointing! ...