Roots Discourse

[webpack-cli] Error: Cannot find module 'webpack'

Hi Everyone,

New to Sage and Yarn. I’ve been reading the forums trying to figure out how to get this all setup and I’m getting an error when I try to run “Yarn Build”

I found some threads that said update node.js. I updated from v12 to v14.16.0, but I dont think that is the issue.

Here are my errors in shell.

C:\Users\brian\Local Sites\sage9\app\public\wp-content\themes\CBCtheme>yarn build

yarn run v1.22.10
$ webpack --progress --config resources/assets/build/webpack.config.js
[webpack-cli] Failed to load ‘C:\Users\brian\Local Sites\sage9\app\public\wp-content\themes\CBCtheme\resources\assets\build\webpack.config.js’ config
[webpack-cli] Error: Cannot find module ‘webpack’
Require stack:

  • C:\Users\brian\Local Sites\sage9\app\public\wp-content\themes\CBCtheme\resources\assets\build\webpack.config.js
  • C:\Users\brian\AppData\Roaming\npm\node_modules\webpack-cli\lib\webpack-cli.js
  • C:\Users\brian\AppData\Roaming\npm\node_modules\webpack-cli\lib\bootstrap.js
  • C:\Users\brian\AppData\Roaming\npm\node_modules\webpack-cli\bin\cli.js
  • C:\Users\brian\AppData\Roaming\npm\node_modules\webpack\bin\webpack.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 (C:\Users\brian\AppData\Roaming\npm\node_modules\webpack-cli\node_modules\v8-compile-cache\v8-compile-cache.js:159:20)
    at Object. (C:\Users\brian\Local Sites\sage9\app\public\wp-content\themes\CBCtheme\resources\assets\build\webpack.config.js:3:17)
    at Module._compile (C:\Users\brian\AppData\Roaming\npm\node_modules\webpack-cli\node_modules\v8-compile-cache\v8-compile-cache.js:192: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)
    at Module.require (internal/modules/cjs/loader.js:952:19) {
    code: ‘MODULE_NOT_FOUND’,
    requireStack: [
    ‘C:\Users\brian\Local Sites\sage9\app\public\wp-content\themes\CBCtheme\resources\assets\build\webpack.config.js’,
    error Command failed with exit code 2.

Any suggestions on what to try next?

1 Like

You probably already know that… but just in case - have you installed the npm packages (yarn install)?
Is there a node_modules/ folder? Was the installation successful?
Would the build work if you run npm install webpack?

If your NODE_ENV is not set right, yarn might not be able to get your devDependencies installed.

Try setting it to “development” and see if you get different results.

Hey All,

Thanks for the input. A couple of notes. The node_modules folder was there, but it was clear none of the dev dependencies were being built. There were only 3 folders after the build. In this scenario I was working on a Windows 10 machine.

So a couple of steps to resolve this resolve this.

  1. set NODE_ENV to development
  2. Yarn Build now throws an error about style sheets
    3.) Open webpack.config.js file in theme-name/resources/assets/build
  3. Comment out the follwoign in webpack.config.js
    new StyleLintPlugin({
      failOnError: !config.enabled.watcher,
      syntax: "scss",

More details on the stylesheet issue here if anyone is intereted.

Stylesheet error

Thanks to everyone for helping me out with this one.