Webpack not found Strapi v4

Output

This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason:
Error: Cannot find module 'webpack'
Require stack:
- D:\Personal Projects\NodeJs Projects\kumudini\kumudini-backend\node_modules\terser-webpack-plugin\dist\index.js
- D:\Personal Projects\NodeJs Projects\kumudini\kumudini-backend\node_modules\terser-webpack-plugin\dist\cjs.js
- D:\Personal Projects\NodeJs Projects\kumudini\kumudini-backend\node_modules\@strapi\admin\webpack.config.js
- D:\Personal Projects\NodeJs Projects\kumudini\kumudini-backend\node_modules\@strapi\admin\index.js   
- D:\Personal Projects\NodeJs Projects\kumudini\kumudini-backend\node_modules\@strapi\strapi\lib\commands\build.js
- D:\Personal Projects\NodeJs Projects\kumudini\kumudini-backend\node_modules\@strapi\strapi\bin\strapi.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)
    at Function.Module._load (internal/modules/cjs/loader.js:725:27)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Object.<anonymous> (D:\Personal Projects\NodeJs Projects\kumudini\kumudini-backend\node_modules\terser-webpack-plugin\dist\index.js:14:40)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)

Package Json File

{
  "name": "test-backend",
  "private": true,
  "version": "0.1.0",
  "description": "A Strapi application",
  "scripts": {
    "develop": "strapi develop",
    "start": "strapi start",
    "build": "strapi build",
    "strapi": "strapi"
  },
  "dependencies": {
    "@strapi/plugin-i18n": "4.0.0",
    "@strapi/plugin-users-permissions": "4.0.0",
    "@strapi/strapi": "4.0.0",
    "mysql": "^2.18.1",
    "sqlite3": "5.0.2"
  },
  "author": {
    "name": "A Strapi developer"
  },
  "strapi": {
    "uuid": "103e366e-beb2-47e8-b4ec-fe8464dac71f"
  },
  "engines": {
    "node": ">=12.x.x <=16.x.x",
    "npm": ">=6.0.0"
  },
  "license": "MIT"
}

Server.js file

module.exports = ({ env }) => ({
  host: env("HOST", "0.0.0.0"),
  port: env.int("PORT", 1337),
  url: "https://custom url",
  admin: {
    url: "/",
    serverAdminPanel: false,
    auth: {
      secret: env("ADMIN_JWT_SECRET", "*custom*"),
    },
  },
});

Tried Commands

npm install
npm run build

Very late to the party but in case someone else encounters this issue, if you’re migrating from 3 to 4, it may help to dump your node_modules, delete package-lock and then reinstall everything.

1 Like