Closed RAzaALy closed 2 years ago
webpack 4
How are you accessing the variables, and can you give us a glimpse of what your env file looks like?
(also, it’s a bit concerning you are using an example file for your actual envs, I’m imagining that may just be a placeholder during development).
Closing due to lack of participation and cannot reproduce.
Feel free to reopen this if you can provide more details, thanks.
Facing the same issue. My configurations are: webpack.config.js:
plugins: [
new DotEnv({ path: `./.env.${env.env}`, systemvars: true }),
new CopyWebpackPlugin({
patterns: [
{
from: path.resolve(__dirname, 'public'),
to: path.resolve(__dirname, 'dist'),
},
],
}),
],
.env.local:
API_BASE_URL=https://my-url
index.js:
const BASE_URL = process.env.API_BASE_URL;
console.log(process.env) //this gives me an empty object
console.log(process.env.API_BASE_URL) //undefined
Not sure what I need to change, thanks for any help/input you have!
webpack-common.js
const path = require('path');
const CopyWebpackPlugin = require('copy-webpack-plugin'); const Dotenv = require('dotenv-webpack');
const CURRENT_WORKING_DIR = process.cwd();
module.exports = { entry: [ '@babel/polyfill', path.join(CURRENT_WORKING_DIR, 'client/app/index.js') ], resolve: { extensions: ['.js', '.json', '.css', '.scss', '.html'], alias: { app: 'client/MONGO_URIapp' } }, module: { rules: [ { test: /.(js|jsx)$/, loader: 'babel-loader', exclude: /(node_modules)/ } ] }, plugins: [ new Dotenv({ path: path.resolve(__dirname, './.env.expample') }), new CopyWebpackPlugin([ { from: 'client/public' } ]) ] };