M
M
mrFlyer2019-02-08 19:16:19
JavaScript
mrFlyer, 2019-02-08 19:16:19

How to overcome the "ReferenceError: process is not defined" error in production?

There is an SSR application on NuxtJS. The plugin "@nuxtjs/dotenv" is used.
I use it in nuxt.config.js:

require('dotenv').config(".env");
/* ---*/
axios: {
        baseURL: process.env.baseUrl,
    },
/* ---*/

Everything works fine on the local machine. And on the combat server, the error "ReferenceError: process is not defined" falls out both during server rendering and client rendering.
All packages are installed both locally and on the server. I start the application in the same way:
npm i
npm run build
npm run start
I can't figure out how to catch this error? Thank you in advance!
Whole config:
const process = require('process');
require('dotenv').config(".env");

module.exports = {
    head: {
        title: 'Заголовок сайта',
        meta: [
            { charset: 'utf-8' },
            { name: 'viewport', content: 'width=device-width, initial-scale=1' },
            { hid: 'description', name: 'description', content: 'Nuxt.js project' }
        ],
        link: [
            { rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' },
            { rel:'Roboto', href:'https://fonts.googleapis.com/css?family=Roboto:400,700&subset=cyrillic'}
        ]
    },
    css: [
        '@fortawesome/fontawesome-svg-core/styles.css',
        'swiper/dist/css/swiper.css'
    ],
    /*
    ** Customize the progress bar color
    */
    loading: { color: '#3B8070' },
    plugins: [
        '@/plugins/global.js',
        '@/plugins/font-awesome.js',
        '@/plugins/axios.js',
        '@/plugins/notifier.js',
        '@/plugins/vee-validate.js',
        {src: '@/plugins/swiper.js',        ssr: false},
        {src: '@/plugins/localStorage.js',  ssr: false},
        {src: '@/plugins/datepicker.js',    ssr: false},
    ],
    modules: [
        '@nuxtjs/style-resources',
        '@nuxtjs/router',
        '@nuxtjs/axios',
        '@nuxtjs/toast',
        ['@nuxtjs/dotenv', { systemvars: true }]
    ],
    styleResources: {
        sass: ['@assets/css/app.scss'],
    },
    toast: {
        position: 'top-right',
        duration: 3500,
    },
    axios: {
        baseURL: process.env.baseUrl,
        credentials : true,
        requestInterceptor: (config, {store}) => {
            config.headers.common['Authorization'] = '';
            config.headers.common['Content-Type'] = 'application/x-www-form-urlencoded;application/json';
            return config
        }
    },
    /*
    ** Build configuration
    */
    build: {
        /*
        ** Run ESLint on save
        */
        extend (config, { isDev, isClient }) {
            if (isDev && isClient) {
                config.module.rules.push({
                    enforce: 'pre',
                    test: /\.(js|vue)$/,
                    loader: 'eslint-loader',
                    exclude: /(node_modules)/
                })
            }
        },
        optimization: {
            splitChunks: {
                chunks: 'all',
                automaticNameDelimiter: '.',
                name: true,
                cacheGroups: {},
                minSize: 100000,
                maxSize: 250000
            }
        },
        maxChunkSize: 250000,
        extractCSS: true
    },
    dev:{
        extractCSS: true
    }
};

Answer the question

In order to leave comments, you need to log in

2 answer(s)
G
grinat, 2019-02-08
@grinat

Cant with the assembly, probably a piece for node.js gets into the assembly for the client, or if the webpack define plugin is used, then the values ​​\u200b\u200bin the config for the prod version are not written there.

V
Vladimir Proskurin, 2019-02-08
@Vlad_IT

Try adding first
const process = require('process');

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question