process is not defined in Vue.js

Viewed 2201

I tried to use the process.env.process.env.VUE_APP_SERVER_URL in my vue project. But I got the error like the following.

Uncaught ReferenceError: process is not defined

It's using the webpack and run by npm start command.

Once you know the solution, please feel free to contact me.

1 Answers

You can add the following code in webpack.config.js.

const webpack = require('webpack');
const dotenv = require('dotenv').config({ path: __dirname + '/.env' })

module.exports = {
   ...
   plugins: [
      new webpack.DefinePlugin({
          'process.env': JSON.stringify(dotenv.parsed),
      }),
   ]
   ...
}
Related