Home > Blockchain >  Webpack not found when deploying using heroku
Webpack not found when deploying using heroku

Time:12-01

I'm trying to deploy an app on heroku, but I'm getting an error when it tried to build the app with the webpack command. I have tried a number of fixes but can't seem to get it to work. I tried running the webpack.js file from node_modules like this node node_modules/webpack/bin/webpack.js but that didn't work either. Any ideas would be greatly appreciated! Here is my package.json file:

{
  "name": "waste-not-client",
  "version": "1.0.0",
  "description": "",
  "private": true,
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "concurrently npm:watch:*",
    "build": "webpack --mode production",
    "watch:compile": "webpack --mode development --watch",
    "watch:serve": "nodemon server/server.js",
    "heroku-postbuild": "npm install && npm run build && node server/server.js"
  },
  "repository": {
    "type": "git",
    "url": "git https://github.com/Blue-ocean-HR/blueocean-client.git"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "bugs": {
    "url": "https://github.com/Blue-ocean-HR/blueocean-client/issues"
  },
  "homepage": "/",
  "dependencies": {
    "@auth0/auth0-react": "^1.12.0",
    "axios": "^1.1.3",
    "compression": "^1.7.4",
    "concurrently": "^7.6.0",
    "cors": "^2.8.5",
    "dotenv": "^16.0.3",
    "express": "^4.18.2",
    "framer-motion": "^7.6.7",
    "nodemon": "^2.0.20",
    "path": "^0.12.7",
    "react": "^18.2.0",
    "react-autocomplete-input": "^1.0.19",
    "react-dom": "^18.2.0",
    "react-router-dom": "^6.4.3",
    "webpack-bundle-analyzer": "^4.7.0"
  },
  "devDependencies": {
    "@babel/core": "^7.12.3",
    "@babel/plugin-syntax-jsx": "^7.18.6",
    "@babel/preset-env": "^7.12.1",
    "@babel/preset-react": "^7.12.5",
    "autoprefixer": "^10.4.13",
    "babel-jest": "^29.1.2",
    "babel-loader": "^8.2.1",
    "compression-webpack-plugin": "^10.0.0",
    "css-loader": "^6.7.1",
    "dotenv-webpack": "^8.0.1",
    "postcss": "^8.4.19",
    "postcss-loader": "^7.0.1",
    "postcss-preset-env": "^7.8.3",
    "style-loader": "^3.3.1",
    "tailwindcss": "^3.2.4",
    "webpack": "^5.75.0",
    "webpack-cli": "^4.10.0",
    "webpack-dev-server": "^4.11.1"
  },
  "engines": {
    "node": "v16.16.0"
  }
}

The error when I try to deploy on heroku:

sh: 1: webpack: not found

CodePudding user response:

Your start script looks like it's designed for development work with live reloading. That's not what you want on Heroku.

You could rewrite your package.json scripts, but the easiest solution is probably to add a Procfile that Heroku will use in preference to your start script, e.g.

web: node server/server.js

You'll also want to remove your heroku-postbuild script entirely. It just repeats two things that Heroku does automatically (installing dependencies and running your build), and it also includes the runtime command that we now have in our Procfile.

  • Related