The problem persists as Vite is failing to load CSS codes enclosed within VUE components

My project is developed using Laravel, Inertia.js with Vue, and Vite for bundling the frontend assets.

Everything seems to be working fine with the application, except when I try to access it from a subdirectory. In this scenario, Vite fails to load the CSS styles defined in the .vue files or components.

This issue results in a blank page being displayed when accessing the URL example.com/subdirectory/login

The browser console displays the following error message:

Uncaught (in promise) Error: Unable to preload CSS for /build/assets/Login.a0d488b1.css d http://example.com/subdirectory/build/assets/app.6486bb89.js:1

This specific case pertains to me trying to access the Login page/component, but failing to load the Login.a0d488b1.css file due to the missing subdirectory prefix in its path.

I am seeking assistance on resolving this issue. Could you please provide guidance on how to tackle this problem?

The content of my vite.config.js file is as follows:

import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';
import vue from '@vitejs/plugin-vue';
import path from 'path';

export default defineConfig({
   plugins: [
       laravel({
           input : [
               // 'resources/sass/app.scss',
               'resources/js/app.js',

               // website
               'resources/sass/website/theme.scss',
               'resources/js/website/main.js',

               
           ],
           refresh: [{
               paths: ['resources/js/**', 'resources/sass/**'],
               config: { delay: 300 }
           }],
       }),    
       
       vue({
           template: {
               transformAssetUrls: {
                   base: null,
                   includeAbsolute: false,
               },
           },
       }),
   ],
   resolve: {
       alias: {
           'ziggy': path.resolve('vendor/tightenco/ziggy/dist'),
           'ziggy-vue' : path.resolve('vendor/tightenco/ziggy/src/js/vue'),            
       }
   }
});

Answer №1

While I don't have a foolproof solution to offer, my search for answers online came up empty on this particular issue. Here's what I can share based on my own experience:

I encountered a similar error in one of my Vue component files, even though there were no style tags present within it. Strangely enough, the Vite build still generated a corresponding CSS file for this component.

Upon closer inspection, I discovered a line inside the compiled CSS file that read

@import url("//hello.myfonts.net/count/3edd2b")
. This snippet originated from an SCSS file I had included globally in my application and imported into the app.js entry point.

It seemed like Vite was having trouble accessing this import properly. The URL itself returned an empty response, which likely compounded the issue at hand.

In the end, removing that problematic import from the SCSS file resolved the CSS compilation errors I was facing. Sometimes, the simplest solutions make all the difference.

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

Remove an owl carousel using Laravel, Vue.js, and Axios

I've implemented a sleek slider on my website to showcase images with accompanying text to visitors. The slider utilizes owl carousel within a vue component and is functioning properly. Now, I'm attempting to add a delete button so that users who ...

Fixing TypeError: Object #<IncomingMessage> has no method 'flash' in ExpressJS version 4.2

Currently, I am utilizing ExpressJS 4.2 and PassportJS for authenticating local users. Everything seems to be working smoothly except for when attempting to display a failureFlash message. Below is my configuration setup, thank you in advance! ==== Necess ...

Customize your Vue 3 application with custom Axios functions for handling GET, PUT,

I am looking to enhance my use of axios by customizing the get, post, and put functions. After performing the axios.create() operation, I want every subsequent get operation to include a then and catch block. import axios from "axios"; export de ...

What are some best practices for creating a Helper in VueJs?

As part of a project, I have developed a method that generates random hexadecimal colors. This functionality will only be used in a few (3 to 5) parts of the project. To keep my main code clean and organized, I would like to separate this color generation ...

Troubleshooting an issue in Chrome with animating the "d" value using Snap.svg

To uncover the issue, try opening in both Chrome and Safari browsers. The logo animation should animate one section at a time like it does in Safari, but in Chrome, the animation seems to freeze. Check out the Snap.svg function responsible for running th ...

Guidelines for iterating through a nested JSON array and extracting a search query in Angular

I'm currently working with a complex nested JSON Array and I need to filter it (based on the name property) according to what the user enters in an input tag, displaying the results as an autocomplete. I've started developing a basic version of t ...

Developing an IF statement in JavaScript that relies on hexadecimal color values

I've created a JavaScript code that changes the background color of my webpage every time it loads: document.getElementById("band").style.background = '#'+(Math.random()*0xFFFFFF<<0).toString(16); To improve visibility, I am aiming t ...

In Angular, the ng-click directive that assigns the value of tab to $index does not seem to be functioning properly

I encountered an issue within my app <li ng-repeat="name in tabs track by $index" ng-class="{selected: tab==$index}" ng-click="tab = $index">{{name}}</li> After clicking on each item, the selected class remains enabled and switching to anothe ...

How to customize the hover and active properties of a checked checkbox in Vue 3 using Tailwind CSS and PUG?

It seems that checkboxes have a level of sophistication that I never anticipated, or perhaps my brain just can't quite grasp the nuances of checkboxes. After spending a significant amount of time researching and experimenting with checkboxes in a Vue ...

Is it possible to achieve a seamless change using show/hide jQuery functions when hovering over an

How can I achieve smooth transitions when using an image map to show a div on hover, similar to the functionality seen on this website: ? Below is my current JavaScript code: var mapObject = { hover : function(area, event) { var id = area.attr ...

AJAX Form Submission for CommentingAJAX allows for seamless form submission

Currently facing an issue with a form submission that is not displaying comments without refreshing the page. When the submit button is clicked, it redirects to the top of the page without executing any actions - no insertion into the database and subseque ...

Accessing the jQuery Ajax success variable

I have a PHP function that returns an array with an element error containing the value 'ERR': var updatePaymentType = function(plan_pt_id, pt_id){ var error = null; var data = new Object() data["function"] = "update"; ...

Remembering Me with Express JWT?

At the moment, my tech stack includes Vue on the frontend and Express on the backend. To manage authentication, I'm utilizing Express's JSONWebToken plugin. However, I'm struggling to securely store the JWT in a cookie and extract the User o ...

Exploring jQuery Mobile: Uncovering the Power of clientX, clientY, and taphold Event

In my current project, I am implementing the taphold event and require the coordinates of the tapped point by the user. However, I have encountered an issue where event.clientX and event.clientY are returning as undefined (you can see the example here: her ...

Issue with manipulating currency conversion data

Currently, I am embarking on a project to develop a currency conversion application resembling the one found on Google's platform. The main hurdle I am facing lies in restructuring the data obtained from fixer.io to achieve a similar conversion method ...

Advanced Techniques: Leveraging Master Layouts, Partial Rendering, and JavaScript Function

Trying to understand the sequence of events when a master page, partials, and JavaScript code are involved. Imagine having a Master page with scripts: <%@ Master Language="C#" ... %> <head> <asp:ContentPlaceHolder ID="HeadContent" run ...

What is the process for incorporating a personalized validation function into Joi?

I have a Joi schema and I am trying to incorporate a custom validator to validate data that cannot be handled by the default Joi validators. Currently, my Joi version is 16.1.7 const customValidator = (value, helpers) => { if (value === "somethi ...

Utilizing JQuery to extract information from a JSON response

I've been struggling with accessing a specific piece of content within a JSON object. This is the code I'm using to fetch the data: function retrieveData(keyword){ $.ajax({ url: "https://openlibrary.org/api/books?bibkeys=ISBN ...

What is the method to extract information from the provided URL?

Hello, I am looking to retrieve system requirements data from . How can I achieve this using JS or react? ...

Guide on dynamically changing the color of polymer 1.0 paper-button from an array of colors

I have an array called buttonColors that contains a set of colors in hex format. I am looking to create paper-buttons, each with the color from the buttonColors array. How can I achieve this in Polymer 1.0? <template is="dom-repeat" items="{{buttonCo ...