Using Vue 2 with Webpack works seamlessly for one application but encounters issues when used for another

I've been struggling with this problem for days now. I'm working on a project that consists of two single-page Vue applications or a two-page application as some might call it. These apps have common functionalities which have been extracted into separate folders like /utilities, /state, and /mixins. Pretty standard setup.

src/
├─ apps/
│  ├─ admin/
│  │  ├─ main.js
│  │  ├─ app.vue      <-- mixins imported
│  ├─ customer/
│  │  ├─ main.js
│  │  ├─ app.vue      <-- mixins imported
├─ mixins/
├─ state/
├─ utilities/
├─ vue.config.js

I've configured webpack to alias these paths so that I can access them without using relative paths.

// vue.config.js
const path = require('path');

module.exports = {
  // Put this in the ASP.NET Core directory
  outputDir: "../wwwroot/app",
  pages: {
    admin: "src/apps/admin/main.js",
    customer: "src/apps/customer/main.js",
  },
  configureWebpack: {
    resolve: {
      alias: {
        '@app': path.resolve(__dirname, 'src/'),
        '@customer': path.resolve(__dirname, 'src/apps/customer/'),
        '@admin': path.resolve(__dirname, 'src/apps/admin/'),
        '@mixins': path.resolve(__dirname, 'src/mixins/'),
        '@utilities': path.resolve(__dirname, 'src/utilities/'),
      }
    }
  }
};

Everything was working fine for the customer app, I could access mixins using:

import { mixin } from '@mixins';

However, I've been facing serious issues with the admin app that I just can't seem to figure out. The vue-cli-service builds the project without any errors, but when I open it in the browser, I just see a blank screen with no errors in the console. Interestingly, I can access both @state and @utilities in the admin app without any problems. It's only the @mixins that is causing issues and I can't pinpoint the exact reason why.

As a sanity check, I copied each mixin to a new folder aliased @common and imported from there in the admin app to see if any specific file was causing the problem. Surprisingly, even after copying all mixins, the issue persisted. I even tried changing one @mixins import in the customer app to @common and the blank screen reappeared without any error. I even tried switching back to relative imports as a last resort - but the issue still persists. It seems like the project breaks down completely when both apps try to import from the mixins folder, which is strange considering it works fine if only one app does it?

I'm at my wit's end with this. Does anyone have any insights into what might be going wrong here? I'm completely lost.

Answer №1

If you find yourself in this situation, ensure that your html code includes the webpacked script chunk-common.js. I made the mistake of including both individual app js files and chunk-vendors.js, but when using mixins in both apps, the entire @mixins folder was moved to a common location where it was inaccessible. Surprisingly, there were no visible errors in the browser console, which made debugging difficult.

The root cause of this issue was somewhat obscured, as other folders containing shared scripts like @utilities and @state continued to function properly without the common script. It's possible that webpack did not extract them due to their smaller size. In any case, it's important to double-check your webpack configuration. Hopefully, this information will save someone else from the same time-consuming problem I faced.

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

Tips for troubleshooting Node.js React Express applications

Having a background in traditional programming, I am used to putting breakpoints in code and having the debugger take me directly to the problematic section when executed. However, as I delve into web app development, it seems that debugging is limited to ...

Do not reveal result of coin flip using Javascript and API

Even though I meticulously copied my professor's parsing process, the display isn't turning out as expected. It seems like something is off in my code. <div class="main"> <p>Heads or tails? click to toss the coin</p> & ...

Troubleshooting AngularJS: Diagnosing Issues with My Watch Functionality

I need to set up a watch on a variable in order to trigger a rest service call whenever its value changes and update the count. Below is the code snippet I have: function myController($scope, $http) { $scope.abc = abcValueFromOutsideOfMyController; ...

Dynamic stacking of buttons in response to user navigation choices

Is it possible to create a navigation bar with 5 buttons using CSS and JS? Here is what I am looking to achieve: Display 5 nav/button options When a user clicks on a button, the other buttons should transition or hide, leaving only the selected button vi ...

What is the best way to eliminate the space between two columns of a row in Bootstrap 5 grid system?

In my quest to achieve the grid layout illustrated in the image below https://i.sstatic.net/4hsjw.jpg .col_1{ background-color: bisque !important; height: 500px; } .col_2 { width: 300px; height: 287px; background-position: cent ...

How can you identify duplicate entries using Mongoose?

I am currently working on a create function and encountering some code that closely resembles this: if(req.body.test !== undefined) { if(--req.body.test EXISTS IN test (model)--) { DO STUFF } else { ...

Components in Angular modules that are loaded lazily with identical names

I have developed an Angular application with multiple lazy-loaded modules. Each of these modules contains different components that are conceptually similar but vary in content. For example, each module may have its own "home" component. Is it advisable t ...

What is the best way to utilize a portion of the data retrieved from an API call as the output for a function?

After extensive research and testing, I have been exploring ways to make API calls in node js. Currently, my focus is on utilizing a portion of the JSON object returned from an API call within a module to generate a Token. var request = require("request") ...

Bidirectional data binding in AngularJS for <option> elements generated from an AJAX request

I have built a Controller called WebsiteController with the following functionality: JApp.controller('WebsiteController', function($scope, $resource) { var UsersService = $resource('/auth/users', {}); $scope.adding = false; ...

Ensure that the date range picker consistently shows dates in a sequential order

Currently utilizing the vuetify date range picker component https://i.stack.imgur.com/s5s19.png At this moment, it is showcasing https://i.stack.imgur.com/GgTgP.png I am looking to enforce a specific display format, always showing the lesser date first ...

Using Node.js to send a response only after every promise has been resolved

I am currently working on a NodeJS Express route where I have encountered an issue. In this route, a function is called multiple times, each returning a Promise. The values from these Promises are then added to an Array and sent back to the client using re ...

Ideal JavaScript data structure for connecting three arrays

My goal is to establish a connection between three arrays in the following manner: arr1 = ['A', 'A', 'B', 'B', 'C', 'C' 'A', 'C'] arr2 = ['a', 'aa', ' ...

AngularJS $routeProvider is experiencing difficulties with its routing functionality

I am a beginner with Angular and I'm trying to understand how multiple routes can lead to the same view/templateUrl and controller. This is what I have written: angular .module('mwsApp', [ 'ngAnimate', 'ngCookies&ap ...

Interactive div containing elements that cannot be clicked

http://codepen.io/anon/pen/zxoYBN To demonstrate my issue, I created a small example where there is a link button within a div that toggles another div when clicked. However, I want the link button to not trigger the toggle event and be excluded from the ...

Custom CSS for the Google Maps Circle Object

Currently, I am utilizing the Google Maps Javascript API v3 Circle object to display circles on the map. I am interested in customizing the CSS of this circle by incorporating some CSS animations. Although I am aware that custom overlays can be used for t ...

Sophisticated sinatra parameter

Creating Dynamic Surveys <script type="text/x-jsrender" id="surveyTemplate"> <li class="question"> <input type="text" name="survey[question]" /> <button class="add_answer">Add Answer</button> <ul> ...

What is the best way to identify a specific list item from a dropdown menu and determine its position on

Check out my jsfiddle for reference. My goal is to calculate scores based on different options selected, specifically relating to radiation types. I'm struggling with assigning a score to each type of radiation and integrating the drop-down menu selec ...

The tabs are visible in the drawer, but the transition is not occurring

I am a beginner when it comes to using material ui. After clicking on advanced sports search, a drawer pops up. I have been trying to incorporate tabs in the drawer, but every time I click on tab two, the drawer closes. In reality, it should switch between ...

Module not discovered by nodeJS within the current directory

In my node application, I am trying to incorporate a module called dishRouter. The file structure looks like this :- Structure The dishRouter is exported from Dishes/index.js and imported into my app.js using the following code: var dishRouter = re ...

Trouble arises with the conditional rendering in vue.js

I'm encountering an issue with rendering a template Even when the condition is TRUE, new data that has been added isn't going through the v-if process. Could someone please shed some light on why this might be happening? To provide further clar ...