spencerlepine / woofer

Dating app for pets - a full stack MERN project. Complete with CI/CD pipeline w/ Jest, GitHub Actions, Docker Hub, and AWS EC2
https://youtu.be/aiJhCoZRc78
2 stars 1 forks source link

webpack .env error #57

Closed spencerlepine closed 2 years ago

spencerlepine commented 2 years ago

Problem

Webpack needs a physical .env file to referenec when running npm run build. OR Webpack can reference the .env values from memory. HOWEVER, docker needs to pass these env variables down as it builds.

Research

https://stackoverflow.com/questions/41359504/webpack-bundle-js-uncaught-referenceerror-process-is-not-defined

Screen Shot 2022-04-17 at 3 14 29 PM
spencerlepine commented 2 years ago

Solution (for Client)

npm i dotenv

Update package.json

"scripts": {
    "start": "npm run dev:client",
-    "build": "dotenv -- webpack --config ./webpack.prod.config.js --mode production",
+    "build": "dotenv -e ../.env -- webpack --config ./webpack.prod.config.js --mode production",
    "dev:client": "webpack serve --config ./webpack.dev.config.js --env development --mode development",
    "test": "jest --detectOpenHandles --runInBand --forceExit",
    "test:watch": "jest --onlyChanged --watch"
  },