Encountering issues during the automated creation of a Nuxt.js application using an Express server

I am attempting to launch Nuxt programmatically from my Express server, but I encounter errors once the application is compiled and I check my browser console:

https://i.stack.imgur.com/MZxHk.png

https://i.stack.imgur.com/sfDIF.png

This is how my nuxt.config.ts file looks like:

import NuxtConfiguration from '@nuxt/config';

/**
 * Configuration for Nuxt.js admin console app.
 */
export const config: NuxtConfiguration =  {
  /**
   * Directory paths options. Remove `rootDir` and `modulesDir` properties if you want to run/build admin console Nuxt app.
   */
  rootDir: 'src/admin-console',
  modulesDir: ['../../node_modules'],
  mode: 'universal',
  /*
  ** Headers of the page.
  */
  head: {
    title: process.env.npm_package_name || '',
    meta: [
      { charset: 'utf-8' },
      { name: 'viewport', content: 'width=device-width, initial-scale=1' },
      { hid: 'description', name: 'description', content: process.env.npm_package_description || '' }
    ],
    link: [
      { rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }
    ]
  },
  /*
  ** Customize the progress-bar color.
  */
  loading: { color: '#fff' },
  /*
  ** Global CSS.
  */
  css: [
  ],
  /*
  ** Plugins to load before mounting the App.
  */
  plugins: [
  ],
  /*
  ** Nuxt.js modules.
  */
  modules: [
    // Doc: https://bootstrap-vue.js.org/docs/
    'bootstrap-vue/nuxt',
    // Doc: https://axios.nuxtjs.org/usage
    '@nuxtjs/axios',
  ],
  /*
  ** Axios module configuration.
  ** See https://axios.nuxtjs.org/options
  */
  axios: {
  },
};

export default config;

To build Nuxt as an Express middleware, here is what I have:

import { Application } from 'express';
import { Nuxt, Builder } from 'nuxt';
import config from '../admin-console/nuxt.config';

/**
 * Builds admin console Nuxt app.
 * @param app Express application instance.
 */
export async function buildAdminConsoleNuxtApp(app: Application) {
  const nuxt = new Nuxt(config);
  try {
    await new Builder(nuxt).build();
  } catch (error) {
    throw new Error(error);
  }

  app.use('/admin', nuxt.render);
}

and it gets registered like this:

await buildAdminConsoleNuxtApp(this.app);

In all the resources I've checked, this seemed to be the typical way to build Nuxt programmatically, so I'm unsure where I may have gone wrong. The built application doesn't respond to click events properly and is not functioning as expected.

Answer №1

The issue stemmed from neglecting to set the config.dev property, as outlined in the official documentation for programmatically running Nuxt.

Having made the necessary adjustment, my functioning code now appears as follows:

import { Application } from 'express';
import { Nuxt, Builder, Generator } from 'nuxt';
import config from '../admin-console/nuxt.config';
import { EnvType } from '../config/types';

/**
 * Builds admin console Nuxt.js/Vue.js application.
 * @param app Express application instance.
 */ 
export async function buildAdminConsoleNuxtApp(app: Application) {
  config.dev = process.env.NODE_ENV === EnvType.PRODUCTION;
  const nuxt = new Nuxt(config);
  try {
    const builder = await new Builder(nuxt);
    await new Generator(nuxt, builder).generate({ build: true, init: true });
  } catch (error) {
    throw new Error(error);
  }

  app.use('/', nuxt.render);
}

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

Establishing a Fresh User with npm Commands

I'm having trouble creating a user with a js file in my package.json scripts. I've set up the script to run with npm run create_admin, but for some reason, the user is not being created and no errors are showing up. After some initial debugging, ...

The base directory is not taken into account by Gulp.src

My project structure looks like this: - _build/ - build-tools/ - gulpfile.js - someFolder/ - excludeFolder/ - index.html I need to move all files except for _build and 'excludeFolder' directory into the _build/release folder. This is the Gul ...

Error: Accessing Undefined Property in Node-SQLite

I recently started developing a REST API for garden-related data collected by an Arduino using node-sqlite3. Basic queries like retrieving all the database information are working fine. However, I am facing challenges when trying to retrieve data based on ...

Display and conceal table columns dynamically in Vue by utilizing the Vuetify data table functionality

Looking for an example: How to show hide columns of vuetify data table using v-select list I have created something similar, but I'm facing an issue where the table doesn't refresh when changing the header data: https://codepen.io/Meff1/pen/vY ...

The node is currently operating on a non-existent version

While attempting to set up Strapi in my Angular project, an error arises: The Node.js version running is 14.20.0 Strapi mandates using a Node.js version between >=16.0.0 and <=20.x.x Kindly ensure that the correct Node.js version is being used The i ...

Dealing with Missing Nested Objects in MongoDB Aggregation

Currently, I am utilizing MongoDB within Node (I believe it is the latest version). Within my database, I have a collection named users. Here is an example object from this collection: { uid: 'FifUPgoJLOLz872', email: '<a href="/c ...

I am encountering a situation in which the controller file is returning empty data when logging the contents of req

User Model const mongoose = require("mongoose"); const userSchema = mongoose.Schema( { name: { type: String, required: true }, email: { type: String, unique: true, required: true }, password: { type: String, required: true }, pic: { ...

What is the best way to initialize cron in Next.js after a server restart without employing a custom server?

Is there a way to initiate cron in Next.js after a server restart without using a custom server? We are utilizing the Next API routes and I am looking for a way to trigger a function after running the npm start command, or alternatively, the npm run dev c ...

The client-side is unable to locate the io component

I have built a basic program with a nodejs consumer that retrieves data from kafka and then sends it to a client using socket.io for rendering the data with d3. Unfortunately, I am encountering an error on the client side indicating that it cannot find io ...

Breaking the line in Vue JS allows for more organized and easier

Snippet of Vue.js code: getTitleText(){ let mainTitle = ""; let getTitle = this.titleText; let countGetTitle = getTitle.split(" ").length; if(countGetTitle > 4){ mainTitle = getTitle.replace(/(\S+\s*){1,4}/g, ...

"Discover the step-by-step process for customizing the icon colors within Bootstrap components

I successfully incorporated a dark mode into my Vue project built with Bootstrap 5.2. However, I am facing an issue while trying to change the color (to be white) of the two icons below: The first one is from a form-select The second one is from an inpu ...

What could be causing the lack of triggering Vue.js beforeUpdate, updated, and activated events during execution?

Can you identify which lifecycle hooks are executed in this vue.js code? beforeCreate created mounted but not: beforeUpdate updated activated Check out the code on jsFiddle var vm = new Vue({ el: '#app', data: function() { return ...

CSS mismatch detected between production and development modes

Currently, I am utilizing the Vuetify framework coupled with custom CSS for a project developed using a webpack template. During development mode, my custom CSS modifications are successfully applied to HTML elements; however, in Production mode, these cha ...

Issue encountered: React module not detected while attempting to execute npm start command

While developing my react app, I encountered an issue when trying to run 'npm start'. The application was working as expected until I faced a bug that prompted me to update my node version for a potential fix. After upgrading to node v16.13.2 and ...

Using a module's internal function as a callback in the "request" operation

Within my primary code, I execute the following: var module = require('./module') module.FooA(module.FooB); The contents of module.js are as follows: var request = require('request'); //using npm "request" exports.FooB = function(d ...

What is the most straightforward method for saving sessions in Connect that is working right now?

I've been searching for session store implementations compatible with Connect in node.js, but haven't had much luck. While Connect-Redis is effective, the dependency on Redis is something I'd prefer to avoid. Sesame/nStore seemed promising, ...

Importing JavaScript files to work with Vue-Router: A Step-by-Step Guide

Seeking guidance on importing JavaScript files correctly throughout my Vue project, including within the components used to implement changes with Vue-Router. Currently, encountering an issue where I must reload the component in order for the JavaScript to ...

Determine the worth of various object attributes and delete them from the list

Currently, my dataset is structured like this: { roof: 'black', door: 'white', windows: 8 }, { roof: 'red', door: 'green', windows: 2 }, { roof: 'black', door: 'green', windows: ...

Node.js unexpectedly experiencing significant performance deterioration

In our current setup, we have an architecture consisting of 2 node processes. The first node process continuously monitors a private API for any changes and transmits them to the second node. The second node is responsible for processing this data, intera ...

Minimize the presence of redundant node_modules in your local development setup

When it comes to compiling SASS, minifying JavaScript, and copying files, I rely on node and gulp. However, the sheer volume of NPM packages (300 to be exact) in each of my 100+ local development projects on OSX is making me question if there's a more ...