Struggling with my `welcome.blade.php` not detecting Vue imported within my Nuxt.js directory

I have been working with Nuxt.js on my Laravel project. Combining them was a necessary step since they each come with their own boilerplate during installation into the project.

I managed to make almost everything work smoothly until I encountered an issue where my welcome.blade.php needed to read my index.vue component located in the resources/nuxt/pages folder.

The current problem I am facing is an "unexpected identifier on line 1 of my public/App.js" file when trying to import Vue.

Import Vue from 'vue'

To compile things, I modified my yarn run dev-nuxt script in the package.json file (simplified | more details available upon request)

    {
    "private": true,
    "scripts": {
        "dev-nuxt": "nuxt",
    },

Prior to that, I used to run yarn run dev

"dev": "npm run development",
"development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",

This would refer to webpack.mix.js. When running yarn run dev, my terminal showed errors like:

Module not found: Error: Can't resolve '~/components/Logo.vue' in 'C:\Users\Owner\Documents\META+LAB\iSTART\resources\pages'
 @ ./resources/pages/index.vue?vue&type=script&lang=js& (./node_modules/babel-loader/lib??ref--4-0!./node_modules/vue-loader/lib??vue-loader-options!./resources/pages/index.vue?vue&type=script&lang=js&) 28:0-41 32:10-14
 @ ./resources/pages/index.vue?vue&type=script&lang=js&
 @ ./resources/pages/index.vue
 @ ./resources/js/app.js
 @ multi ./resources/js/app.js ./resources/assets/app.scss

I also noticed that my webpack.mix.js did not include references to my nuxt.config.js (simplified | more details available upon request)

    const pkg = require('./package')
    const path = require('path');

    module.exports = {
      mode: 'spa',
      /*
      ** srcDir points to where nuxt will be compiled by yarn nuxt-dev
      */
      srcDir: 'resources/',
      /*
      ** buildDir is where my nuxt code will be compiled to 
      */
      buildDir: 'public/js/',

      ** Nuxt.js modules
      */
      modules: [,
        // Doc: https://bootstrap-vue.js.org/docs/
        'bootstrap-vue/nuxt',
        'nuxt-babel'
      ],

This file refers to my .babelrc, which should compile my vue into my App.js (simplified | more details available upon request)

    {
      "env": {
        "test": {
          "presets": [
            [
              "@babel/preset-env",
              {
                "targets": {
                  "node": "current"
                }
              }
            ],
            "@nuxt/babel-preset-app"
          ]
        }
      }
    }

So I'm uncertain about why this error is occurring. Could it be due to incorrect setup in either my nuxt.config.js or my .babelrc?

Here is how my welcome.blade.php looks like:

    <!doctype html>
    <html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
        <head>
            <meta charset="utf-8">
            <meta name="viewport" content="width=device-width, initial-scale=1">

            <title>Laravel</title>

            <!-- Fonts -->
            <link href="https://fonts.googleapis.com/css?family=Nunito:200,600" rel="stylesheet" type="text/css">
        </head>
        <body>
            <div id="app">
                 <index></index>
            </div>
            <script src="/js/App.js"></script>
        </body>
    </html>

When compiling nuxt with yarn run dev-nuxt, as specified in my package.json, I can see my index.vue component perfectly on a certain port, but I cannot access this component when running php artisan serve.

I suspect that there might be some misconfiguration or additional packages that need to be installed.

For your reference, here is my complete package.json:

    "devDependencies": {
        "@vue/test-utils": "^1.0.0-beta.27",
        "axios": "^0.18",
        "babel-core": "7.0.0-bridge.0",
        "babel-jest": "^23.6.0",
        "bootstrap": "^4.0.0",
        "cross-env": "^5.1",
        "jest": "^23.6.0",
        "jquery": "^3.2",
        "laravel-mix": "^4.0.7",
        "lodash": "^4.17.5",
        "nodemon": "^1.18.9",
        "popper.js": "^1.12",
        "resolve-url-loader": "^2.3.1",
        "sass": "^1.15.2",
        "sass-loader": "^7.1.0",
        "vue": "^2.6.2",
        "vue-jest": "^3.0.2"
    },
    "dependencies": {
        "@babel/core": "^7.2.2",
        "babel-loader": "^8.0.5",
        "bootstrap": "^4.1.3",
        "bootstrap-vue": "^2.0.0-rc.11",
        "cross-env": "^5.2.0",
        "node-sass": "^4.11.0",
        "nuxt": "^2.4.0",
        "vue-loader": "^15.6.2"
    }

Answer №1

When it comes to HTML, Vue initialization is crucial at the #app within a script tag. Without this step, Vue may not be properly initialized. To achieve this, you can use the following implementation:

let app = new Vue({ el : "#app' });

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

The animation feature on the slideshow is dysfunctional

For this Vue component, I attempted to create a slideshow. The process is as follows: 1) Creating an array of all image sources to be included (array: pictures) 2) Initializing a variable(Count) to 0, starting from the beginning. 3) Adding v-bind:src=" ...

Laravel's Vue component is experiencing issues with loading Axios response data

Hey everyone, I hope you're all doing well! I'm facing a bit of an issue with passing data from an axios response to the data property. The data is successfully fetched from the database and displayed in the console, but when I try to display it ...

What is a functional component in defineSlots?

With the latest version of Vue SFC (3.3+), slot scope has become type safe with the introduction of defineSlots. Is there a way to achieve the same type safety for slots in functional components as well? export default defineComponent({ name: 'MyCompo ...

Leveraging the orWhere clause in Eloquent

I have two tables: courriers(courrier_id, repondre ..) and reponses(reponse_id, structure, courrier_id) connected through a one-to-many relationship (where 1 courrier can have several reponses). I am looking to retrieve the courriers where courriers.repond ...

Click on each item within the v-for loop to gather relevant information, and subsequently iterate through the collected data

Within a v-for loop, I have implemented a button that, when clicked, retrieves specific data. The objective is to display this data below or in place of the clicked button. <div v-for="(item, index) in items" :key="index"> <button @click="fetch ...

My Vue.js accordion menu component is experiencing issues with toggle flags, causing it to malfunction

I have been working on my test case using Vue and I recently created a component called MultiAccordion. My intention was to open each slide based on the value of the status[index] flag. However, I am encountering an issue as this component does not seem ...

Guide to resolving a blank webpage issue post running 'npm run build'

I am currently in the process of working on a project that involves Vue and Firebase. Unfortunately, I have encountered an issue where my development server is no longer rendering new routes from my Vue router after building and deploying to production. F ...

Generate a text box that only accepts numbers

I'm in the process of creating a numeric-only input field using VueJS. It's mostly functioning correctly, but there is an issue that needs to be addressed: SUCCESS: Inputting 12 into the text field results in both the VueJS value and visual dis ...

Inquiring about Vue component prop defaults and detecting when a user has not assigned a value

1. I am looking for a way to set a default value for a component prop in Vue 2. Take, for example, a basic movies component that can be utilized like this: <movies year="2016"><movies> Vue.component('movies', { props: ['yea ...

Dynamically generate Nav List Items in Vue.js based on the paths of route children

I am attempting to create a dynamic navigation list using the routes defined in my routes.js: const routes = [ { path: '/', component: () => import('layouts/MainLayout.vue'), children: [ { ...

Using Vue.js to create numerous modal popups

Currently, I am using Vue.JS for a research project at my workplace. My focus right now is mainly on the front-end. I have a table with several entries, and when a row is clicked, I want a modal popup window to display further details about that specific ...

Tips for displaying an associative object array as td elements within a tbody in Nuxt

I'm having trouble displaying the property of an associative object array in my code. I attempted to utilize a v-for loop and wanted to showcase the property information within the td elements of a tbody. I am aware that v-data-table components have a ...

Using VueJS3 in conjunction with leaflet results in an issue

Looking to integrate interactive maps into my VueJS3 application. Successfully implemented the following code: <template> <div id="mapContainer"></div> </template> <script> import 'leaflet/dist/leaflet.css&a ...

Using JavaScript build-in functions in a Vue template allows for enhanced functionality and

Is there a way to utilize JavaScript built-in functions within a Vue template? {{ eval(item.value.substring(2)) }} I attempted to use the JS function eval() in {{}}, but encountered several errors such as: [Vue warn]: Property or method "eval" i ...

The content will only be visible when a comment is added and then removed

Currently, I am in the process of implementing an expansion panel that triggers an API call upon being clicked. This call then populates the v-card and v-layout components with the response data. However, a challenge I am encountering is that initially, th ...

Leveraging the source of an image from asset variables

Lately, I've been experiencing issues with displaying images on my page, specifically when trying to show a list of images. The problem arises when attempting to store the image URL in a variable or object instead of hardcoding it directly into the s ...

Passing components through props in Vue 3

In my previous Vue 2 project, I had implemented a custom routing solution which sometimes required passing components as props. <template> <div> <component :is="component" :data="componentData"/> </ ...

Is there a way for me to gain entry to this array in vuejs?

Can anyone help me with accessing the objects in this array? I am using laravel, inertiajs, and vuejs. I am passing a variable from a laravel controller to a vuejs component with inertia.js. https://i.stack.imgur.com/p7yjL.png https://i.stack.imgur.com/y ...

The following error occurred while running the command "php artisan ui vue get": ErrorException - Unable to open stream: File

Trying to set up VueJS for my Laravel project, but encountered an error when running php artisan ui vue: Can someone please advise on how to resolve this issue? Thank you. ErrorException > copy(D:\Code\Hung's Friend\management&bso ...

Retrieving the internationalization (i18n) locale language from the Pinia store

I am attempting to retrieve the value of the i18n locale language from my pinia store, however, an error is occurring Uncaught Error: [ ...