Vue multi-page application encounters compilation errors when attempting to include CSS within the <style> elements

Within my MPA app, I have integrated vue.js as a vital component. Below is a simple test setup:

  1. the relevant sections of my template
....
<div id='app-basket-checkout'>
    <h1>Expecting Something Special</h1>
</div>
....
  1. pageBasketCheckout.js (similar to my app.js)
import Vue from 'vue'
import AppBasketCheckout from './BasketCheckout.vue'
import './dummyScss.css'

Vue.config.productionTip = false

new Vue({
    render: h => h(AppBasketCheckout)
}).$mount('#app-basket-checkout')
  1. the component
<template>
<div id="app-basket-checkout">
    {{msg}}
</div>
</template>
<script>
export default {
    name: 'AppBasketCheckout',
    components: {

    },
    data() {
        return {
            msg: 'Hello'
        }
    }
}
</script>
<style scoped>
</style>

The above code successfully renders on the front end, displaying an additional div with the word "Hello" inside.

However, when I incorporate CSS into the style tag:

<template>
<div id="app-basket-checkout">
    {{msg}}
</div>
</template>
<script>
export default {
    name: 'AppBasketCheckout',
    components: {

    },
    data() {
        return {
            msg: 'Hello'
        }
    }
}
</script>
<style scoped>
    body {
        font-family: Arial, Helvetica, sans-serif;
        line-height: 1.4;
    }
</style>

This action triggers an error in Chrome:

Uncaught Error: Cannot find module './BasketCheckout.vue?vue&type=style&index=0&id=2711cf65&scoped=true&lang=css&'
    at webpackMissingModule (VM45512 BasketCheckout.vue:4)
    at eval (VM45512 BasketCheckout.vue:4)
    at Module../src/BasketCheckout.vue (pageBasketCheckout.bundle.js:40)
    at __webpack_require__ (index.bundle.js:4312)
    at eval (pageBasketCheckout.js:3)
    at Module../src/pageBasketCheckout.js (pageBasketCheckout.bundle.js:29)
    at __webpack_require__ (index.bundle.js:4312)
    at checkDeferredModulesImpl (index.bundle.js:4453)
    at webpackJsonpCallback (index.bundle.js:4435)
    at pageBasketCheckout.bundle.js:9

This error only occurs when styling is added to the component. Below is my webpack.config.js:

const path = require('path');
// webpack setup example below
// modify as required for projects
module.exports = {
    // config options
};

It seems like the issue may be related to the VueLoaderPlugin which is responsible for splitting the script into separate parts for template, logic, and style. It appears that the style part is not being properly bundled. Further investigation is needed.

Answer №1

Only the current component (and its child components' root nodes) will be affected by the Scoped CSS rules.

Your Vue instance is being mounted at #app-basket-checkout, which is already nested inside a <body> element.

If you want to style the <body>, make sure to use a global stylesheet that is imported in your app.js, instead of a subcomponent.

Alternatively, you can also apply class-based styling to a specific node within your Vue instance to achieve the desired look.

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

Styling in Next.js with conditions

I am attempting to create a scenario where a link becomes active if the pathname matches its href value. function Component() { const pathname = usePathname(); return ( <div className="links"> <Link href="/"> ...

Tips for adjusting the color using inline CSS

Currently, I have a div styled with blue color using CSS. However, I now require the ability to dynamically change this color. My plan is to retrieve the desired color from a database and use its hexadecimal code in place of the default blue. What is the ...

Dynamic HTML binding with v-model in Vue JS allows for seamless two-way

I recently incorporated Vue Js into my main MVC application. I want to be able to bind a Vue Js v-model to dynamically loaded HTML from a partial view. For example, in my partial view, I have the following: <input type="text" id="firstNam ...

Incorporating personalized CSS and JavaScript into Shopify

Currently, my project involves integrating vertical tabs into a Shopify page that is utilizing the 'Atlantic' theme. Since this particular theme doesn't come with vertical tabs built-in, I have incorporated external JS and CSS files known as ...

The highlight_row function seems to be delayed, as it does not trigger on the initial onClick but works on subsequent clicks. How can I ensure it works properly right from the first click?

I developed an application using the Google JavaScript Maps API to calculate distances between addresses. I've encountered a bug where the row in the table is not highlighted on the first click, requiring a second click for the highlighting to take ef ...

Tips for optimizing background images for various screen sizes?

I'm experiencing an issue with my background image where the head is being cut off on larger screens. Is there a way to ensure that the entire picture is always displayed regardless of screen size? The initial property for background-size is set to co ...

Adjust the dimensions of the thead, tbody, and td elements on the fly

I've implemented this property in a .css file on the table shown below and there are 9 records. .fixed tbody td, thead th { width: 5.2%; float: left; } In my scenario, when there are 4 columns, the width should be 23.2%; for 5 columns ...

Show only the items in bootstrap-vue b-table when a filter is actively applied

How can I set my bootstrap-vue b-table to only show items when a filter is applied by the user (i.e., entered a value into the input)? For example, if "filteredItems" doesn't exist, then display nothing? This is primarily to prevent rendering all rows ...

divs aligned at the same vertical position

Struggling for days to align buttons vertically, I have tried various approaches without success. I attempted using position: absolute; bottom: 0; on the parent with position: relative; set. @import url('https://fonts.googleapis.com/css?family=Mon ...

I have a specific resolution in mind where I want to run jQuery code during window scrolling

I have a jQuery code that I want to run only when the resolution is greater than 950px. If not, I risk losing the responsive logo. My goal is to create a navigation bar similar to the one on the Lenovo homepage. $(document).ready(function(){ //left ...

What is the reason for CSS to be included in the installation process when running npm install with [someLibraryName

After executing the following command: npm install vue-material I noticed that it installed and replaced some of the css styles in my application, leading to conflicts. To resolve this issue, I had to manually search for the specific piece of css and ove ...

The issue with clip-path not functioning correctly in Safari persists

My list of clipped elements is causing an issue when using the CSS3 clip-path method to clip an image into an SVG path. The clipping works perfectly, but in Safari (V 12.1.4), the position of the clipped element changes with each box. The element ...

using a tag in flex can disrupt the arrangement of the box's design

What could be the reason for this issue? Is it possible to make the hyperlink appear inline with the rest of the text? .test { padding: 25px; display: flex; height: 100%; text-align: center; font-size: 25px; font-weight: 600; ...

Tips for creating a full-screen background image using HTML and CSS

I am looking to achieve a full-screen background image using HTML and CSS. I have configured all the necessary properties for the background image. Here is where my background image is located: [![enter image description here][1]][1] I have attempted to ...

Leveraging background images in HTML and CSS to create interactive clickable links

I'm attempting to create the illusion of a clickable background image using HTML and CSS, following a tutorial I found here. Unfortunately, I'm encountering two issues: 1) The link is not fully covering the background image 2) The link does not ...

Selecting the label "for" will activate both the anchor tag and input tag simultaneously

It seems like I'm having trouble making this work, and it appears to not be possible. That's why I'm reaching out for help... Here is the CSS that is being used: label.btn { cursor:pointer; display:inline-block; } label.btn>inpu ...

Troubleshooting a mapping problem with CSS elements

While building my website, I have successfully mapped the elements by ID for all alphabet letters except A. When clicking on the letter A, it does not go to the respective elements. Can anyone please help me find a solution? Visit this link for reference ...

Map / Area enveloped in darkness

I'm currently working on a map that includes an area, but I'd like to add a shadow effect around it. I'm struggling to figure out how to achieve this. <map name="map_bottom"> <area id="area_bottom" shape="poly" coords="0,0,0,37 ...

Design a captivating Profile Picture form using HTML and CSS styling

In my form, I am looking to include a user's Profile picture which should be displayed in either a circular or rectangular shape. Initially, the image area will show a black background or a placeholder image. When the user clicks on this area, they sh ...

NodeJS is facing a severe challenge in properly rendering HTML and its accompanying CSS code, causing a major

Once upon a time, I built a beautiful website while practicing HTML, CSS, and JS. It had multiple web pages and used Express for the backend. Unfortunately, I lost all the files associated with it and took a break from web programming for some time. Now, w ...