Encountered a surprising "import" token within the VueJS router using Laravel Mix and eslint

I recently set up eslint in my Laravel project, which uses VueJS and Vue-Router on the front-end. However, I encountered an issue when I added the mix.webpackConfig block to the webpack.mix.js file. The problem arose with the ES2015 import() function that I use to asynchronously load Vue components.

const mix = require('laravel-mix');

/*
 |--------------------------------------------------------------------------
 | Mix Asset Management
 |--------------------------------------------------------------------------
 |
 | Mix provides a clean, fluent API for defining some Webpack build steps
 | for your Laravel application. By default, we are compiling the Sass
 | file for the application as well as bundling up all the JS files.
 |
 */

mix.webpackConfig({
  module: {
    rules: [
      {
        enforce: 'pre',
        test: /\.(js|vue)$/,
        loader: 'eslint-loader',
        exclude: /node_modules/
      }
    ]
  }
})

mix.js('resources/js/app.js', 'public/js')
  .sass('resources/sass/app.scss', 'public/css');

If I remove the mix.webpackConfig() block, everything works as expected. It's puzzling why adding eslint-loader would cause babel to break in this case.

This is the specific file where I utilize the import() function. While someone else faced a similar issue due to a filename typo, I have confirmed that my filenames are accurate.

import Vue from 'vue'
import Router from 'vue-router'
import App from './views/App.vue'
import Home from './views/Home.vue'

Vue.use(Router)

export default new Router({
  mode: 'history',
  base: process.env.BASE_URL,

  routes: [
    {
      path: '/',
      name: 'home',
      meta: { layout: 'no-sidebar-no-container' },
      component: Home
    },
    {
      path: '/login',
      name: 'login',
      meta: { layout: 'no-sidebar' },
      component: () => import('./views/Login.vue')
    },
    {
      path: '/admin',
      name: 'admin',
      meta: { layout: 'no-sidebar' },
      component: () => import('./views/Admin.vue')
    },
    {
      path: '/events',
      name: 'events',
      meta: { layout: 'no-sidebar' },
      component: () => import('./views/Events.vue')
    },
    {
      path: '/course/:courseId',
      name: 'course',
      component: () => import('./views/Course.vue')
    },
    {
      path: '/edit/course/:courseId',
      name: 'edit-course',
      meta: { layout: 'no-sidebar' },
      component: () => import('./views/Admin/EditCourse.vue')
    },
    {
      path: '/edit/course/newcourse',
      name: 'edit-newcourse',
      meta: { layout: 'no-sidebar' },
      component: () => import('./views/Admin/EditCourse.vue')
    },
    {
      path: '/edit/eventspage',
      name: 'edit-eventspage',
      meta: { layout: 'no-sidebar' },
      component: () => import('./views/Admin/EditEventsPage.vue')
    }
  ]
})

Answer №1

Unfortunately, I couldn't find the solution to my problem initially, but I managed to resolve it by utilizing 'laravel-mix-eslint' instead. For a detailed explanation, you can refer to this link:

My updated code snippet looks like this now:

require('laravel-mix-eslint');

mix.js('resources/js/app.js', 'public/js')
  .eslint()
  .sass('resources/sass/app.scss', 'public/css');

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

Facing the issue of not being able to overwrite the default initialized data (variable) in VUE.JS 2 when using the

Situation I created a generic modal component that uses a global bus (empty VUE instance) to communicate with the modal component from any other component that utilizes it. Problem In the Mounted() or Created() hook for the Modal.VUE component, I am att ...

Retrieving data from dynamically generated input fields within a table

I currently have a table in my web application <form id="project-form"> <table id="project-table" class="table table-striped table-inverse table-responsive"> <caption>Projects</caption> ...

Error in hover feature not performing to expectations

Check out my jsfiddle link: http://jsfiddle.net/ganganp/x62wR/5/ $('#rotator0 div').hover( function () { ssrc = $(this).find('img').attr("src"); valt = $(this).find('img').attr("alt"); ...

Display content when tab is chosen (Foundation)

I have a question regarding the use of Zurb Foundation 6 Tabs and some JavaScript functionality. Below is the HTML code for a layout with 3 tabs: <ul class="tabs" data-tabs id="myTabs"> <li class="tabs-title is-active"><a href="#pa ...

Embracing the Quirks of JSON: A Call for a

Currently, I am in the process of developing a webpage that involves incorporating four distinct JSON entities (objects, arrays). Excuse my lack of appropriate jargon. Upon receiving the JSON data, it is structured as an object with numerous sub-objects, ...

Issue encountered when trying to attach a hover event to the items in a comb

Currently, I am facing a specific situation. The requirement is to display a custom tooltip when the mouse hovers over the combobox items (specifically the "option" tag). Initially, my solution involved using the title tag. While this method worked effecti ...

Displaying the HTTP response on the webpage renders as plain text

I encountered an issue while trying to forward a request from a proxy server and display the response in the browser. When I use res.write(data) to render the response, it appears as plaintext instead of rendered HTML: http.createServer(function targetSer ...

The asynchronous `beforeEach` function in the router activates two different

I'm facing an issue where two routes are being triggered when I'm trying to wait for an asynchronous response in my route guard. The problem arises when the page loads, with the "/" route being hit instantly followed by the targeted route. router ...

Turn off JavaScript in the HTML submitted by users

Imagine a scenario where users can input any HTML code into their 'profile' section on a website. How can I ensure that any embedded JavaScript in this HTML does not run? Is it possible to place an infinite loop for(;;); somewhere as a preventiv ...

Check to see if the function that was brought in is being used

Currently, I am attempting to verify whether a composable's method is being invoked from my store. Below is the code snippet I am working with: /stores/ui: import { defineStore } from 'pinia'; import { useUtils } from '@/composables/ut ...

Discover how to modify the URL in Angular

There are two distinct projects under consideration. Authentication Project: is hosted at http://localhost:4200. This project contains a login page where users can input their credentials to sign in. Upon successful login, the user will be redirected to ...

Having trouble with JavaScript's array sorting function

Currently, I am attempting to organize an array of objects based on the attribute page, and I am doing this within a computed property using Vue. The function I am utilizing involves building the objects in the following manner: sorted: function(){ ...

Why does jQuery constantly add a cache buster to my CDN script URLs?

My current script utilizes $.get( ... ) to retrieve HTML content from my server and inject it into a <div> using $.html. I have noticed that when the pulled HTML contains <script> tags, jQuery automatically adds a cache buster parameter to the ...

Encountered a fatal error while running Vue Cli Serve due to an invalid JavaScript size issue, throwing a

Having trouble serving or building my Vue app, I keep encountering the following error: INFO Starting development server... [70%] sealing (finish module graph ESLintWebpackPlugin_1) # # Fatal error in , line 0 # Fatal JavaScript invalid size error 16922 ...

What is the best way to transfer weather data from a server to an HTML text area box?

Recently, I delved into the world of expressJS to set up a local server (localhost:3000). With the power of JavaScript (specifically in a file named app.js), I was able to send simple messages like "Hello World" to the browser. However, now I find myself f ...

Join the geomarkers in two datasets using connecting lines

I am currently developing a leaflet.js map incorporating two distinct sets of JSON data layers stored as js-files. The first dataset comprises the geographical locations of various newsrooms along with their respective IDs, while the second dataset contai ...

When a div is modified through an ajax function, I aim to activate a JavaScript function

Is there a way to automatically execute a javascript function once the status updates to "Upload successful"? I am uncertain about how to accomplish this task. Following a multi file upload, the status will switch based on whether it was successful or en ...

Javascript class for creating random quotes

I am utilizing the JavaScript fetch API to display a random quote. The quote changes upon page load, however, I encounter a type error when clicking on the new quote button. Error message: TypeError: Cannot read properties of undefined (reading 'len ...

Tips on uploading several csv files in Laravel utilizing axios (Vue.js) and importing through Laravel Excel

Vue.js has been my go-to framework for development, and recently I encountered an issue with file submission using axios. Despite trying to append files to FormData, the functionality seems to be failing. Currently, the only outcome I achieve is displaying ...

Create a fresh array by extracting information from a different array column using the .map() function in Vue.js and Laravel

Here is the array I am working with: [ {product: "banana", quantity: "0", price: "32"} {product: "tomato", quantity: "1", price: "45"} {product: "mango", quantity: "2", price: "56"} ] My goal now is to create a new array containing only the product va ...