SSR not working properly in Nuxt 3

Currently facing an issue where I am unable to access my private environment variables. I understand that I can only retrieve them when my page is server-side rendered (SSR). Strangely, even though I have never disabled SSR, when I log console.log(process.server), it always returns false.

Here is a snippet of my nuxt.config.ts file:

// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
    ssr: true,
    routeRules: {
        '/portal/**': { ssr: false },
        '/checkout/**': { ssr: false }
    },
    runtimeConfig: {
        stripeKey: '',
        public: {
            API_BASE_URL: process.env.API_BASE_URL || "http://192.168.1.100:8000/api",
        }
    },
    modules: [
        '@nuxtjs/i18n',
        '@pinia/nuxt',
    ],
    css: [
        '@/assets/css/main.css',
        '@/assets/css/colors.scss',
        'vuetify/lib/styles/main.sass',
        'primevue/resources/themes/lara-light-blue/theme.css',
        'primevue/resources/primevue.css',
        'primeicons/primeicons.css',
        '@fortawesome/fontawesome-svg-core/styles.css'
    ],
    build: {
        transpile: [
            'primevue',
            'vuetify'
        ]
    },
    postcss: {
        plugins: {
            tailwindcss: {},
            autoprefixer: {},
        },
    },
    app: {
        head: {
            script: [{ src: "https://js.stripe.com/v3/" }],
            title: '',
            meta: [

                {
                    name: 'color-scheme',
                    content: 'only light'
                }

            ],
            link: [
                {
                    href: 'https://fonts.googleapis.com/css?family=Material+Icons|Material+Icons+Outlined',
                    rel: 'stylesheet',
                }
            ]
        }
    },
    i18n: {
        lazy: true,
        langDir: "locales",
        strategy: "no_prefix",
        locales: [
            {
                code: 'en',
                iso: 'en',
                name: 'English',
                file: 'en.json'
            },
            {
                code: 'nl-Nl',
                iso: 'nl-NL',
                name: 'Dutch',
                file: 'nl-NL.json'
            }
        ]
    }
})

Answer №1

When you open your browser (referred to as "the client-side"), using console.log(process.server) will always display false.

To see the output as true, check your server console in the terminal. However, if you execute this log command within a "client-only" component/plugin or during a lifecycle hook such as onMounted, it won't show up.

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 type 'true | CallableFunction' does not have any callable constituents

The error message in full: This expression is not callable. No constituent of type 'true | CallableFunction' is callable Here is the portion of code causing the error: public static base( text, callB: boolean | CallableFunction = false ...

Transferring data from a text area to a table with AngularJS

Creating a C# MVC App with AngularJS My goal is to populate a table with values entered in a text area using Angular. Here is the process: Users input values into a text area like this: A B C When a user clicks a button, a modal window should open and ...

The onClick event in React/NextJS is not functioning properly when applied to an external component

One dilemma I am facing involves my main page and a button component that I have created to be reused throughout my project. Strangely, when I add the onClick event to the external component, the click event does not seem to work. However, if I create the ...

New elements can be inserted at the rear of the queue while older elements are removed from the front of the queue

I'm new to JavaScript and currently working on a task involving queues. Here is the task description: Create a function called nextInLine that takes an array (arr) and a number (item) as parameters. The function should add the number to the end of ...

vue and nginx: mismatched route

I'm currently in the process of setting up Vue (version 2.1.x) with Nginx (version 1.10.2), and I have the following configuration: location / { root /var/lib/myRepo/dist/; index index.html; } Everything works perfectly when accessing &ap ...

Encountering difficulty retrieving the value of a hidden input with jQuery's find method

When a user clicks on the delete icon, I want to retrieve the value of the hidden input inside the "delete" class. However, I am getting an undefined result. Can someone please guide me on where I might be going wrong? <table class="items-list"> ...

Testing a subordinate function within the main method that involves HTTP request authorization

Dealing with a tricky situation here, hoping for some guidance. So I'm working with a main method that serves as an api endpoint. This method calls another function to check if the user is authorized to access this endpoint or not. The sub-method, r ...

Loop through the elements retrieved by the `getElementsByName` method in

My goal is to access each node by elementName using the following JavaScript code: function myFunction() { var h1 = document.getElementsByName("demoNode"); for (var i = 0; i < h1.length; i++) { if (h1[i].name == "demoNode") { var att ...

Is it possible to modify the numerical values within TimeCircles.js?

I have integrated the TimeCircles.js plugin into a Persian website and need to convert Persian numbers to English. I already have a function that replaces each digit with the appropriate English number. I am able to successfully convert the text inside t ...

ag-Grid incorporating new style elements

For my Angular application, I have a simple requirement of adding a CSS class when a row expands or collapses to highlight the row. I attempted to use gridOptions.getRowClass following the documentation at https://www.ag-grid.com/javascript-grid-row-styles ...

Checking TinyMCE to ensure it handles empty inputs properly

I find TinyMCE to be a highly effective WYSIWYG editor. The editor functions well, but I encounter an issue when trying to check if it is empty. Challenge I am in need of validating the content input in the TinyMCE textarea to ensure that something ha ...

What is preventing me from displaying my paragraph?

I have some content that I want to show a paragraph with the class paragraphtoggle when clicked, but it's not working as expected. Here is what I have tried: https://example.com/jsfiddle HTML <div class="enzimskiprogramindex herbaprogramindex he ...

What are some solutions for resolving a TypeError in the created hook of a Vue.js application

Oops, there seems to be an error: vue.js:597 [Vue warn]: Error in created hook: "TypeError: handlers[i].call is not a function" found in ---> <StageExecs> vue.js <div id="vue-job"> <div class="row"> <h3>test</ ...

Ways to extract information immediately after using the .load method

Is there a way to instantly store data from .load in JavaScript? Whenever I use .load within a JavaScript function to retrieve content from the server and display it on the browser page, the content does not update immediately. It's only when the fu ...

How can we trigger a function once an ajax request has finished, without directly interacting with the ajax

I am facing a challenge where I need to trigger a JS function after an ajax call is completed, specifically when filtering posts in WordPress. The issue lies in the fact that the ajax filter tool in use is part of a WordPress plugin that cannot be modified ...

Is there a way to keep the text animation going even when I'm not hovering over it with the cursor?

Is there a way to make text continue animating on the page even when the cursor is not placed on it? I understand the hover function, but how can I ensure the text keeps animating without interruption? $(document).ready(function () { $("#start&q ...

Is it possible to retrieve a local variable from a JavaScript function and utilize it outside of its

I've been struggling for hours to access a local variable outside of a function, but I can't figure out where I went wrong. Here's the code: Here's my edited code: if (lastMsg.toUpperCase().indexOf("@TEST") > -1) { var myPy ...

Can jQuery script be used within a WordPress page for inline execution?

Can jQuery be executed in the middle of a page (inline)? I attempted to run the following code within a custom WordPress template.... <script type="text/javascript"> jQuery(document).ready( function() { jQuery(".upb_row_bg").css("filter","blur(30 ...

To enhance the MUI v5 table row, simply apply a border when the mouse hovers

After working on creating a table with Material UI v5, I encountered an issue where I wanted to add a blue border to the table row when the mouse pointer hovered over it. I attempted several methods and did thorough research, but unfortunately, I was unab ...

Error encountered while attempting to load background images from .json dataset

Currently, I am fetching data from a .json file and utilizing a v-for to loop through each object and generate a card for them individually. A strange issue has arisen that is leaving me puzzled: Upon refreshing the page, the background-size COVER no l ...