next.js: Cannot find module 'webpack' in CI environment

Bug report

Describe the bug

In CI environments, when initially trying to start the server after build, it errors out with the following error:

ERR Error: Cannot find module 'webpack'
ERR Require stack:
ERR - /home/vcap/deps/0/node_modules/mini-css-extract-plugin/dist/index.js
ERR - /home/vcap/deps/0/node_modules/mini-css-extract-plugin/dist/cjs.js
ERR - /home/vcap/deps/0/node_modules/@zeit/next-css/css-loader-config.js
ERR - /home/vcap/deps/0/node_modules/@zeit/next-sass/index.js
ERR - /home/vcap/app/next.config.js
ERR - /home/vcap/deps/0/node_modules/next/dist/next-server/server/config.js
ERR - /home/vcap/deps/0/node_modules/next/dist/next-server/server/next-server.js
ERR - /home/vcap/deps/0/node_modules/next/dist/server/next.js
ERR - /home/vcap/app/routes/next.js
ERR - /home/vcap/app/helpers/startServer.js
ERR - /home/vcap/app/server.js
ERR     at Function.Module._resolveFilename (internal/modules/cjs/loader.js:625:15)
ERR     at Function.Module._load (internal/modules/cjs/loader.js:527:27)
ERR     at Module.require (internal/modules/cjs/loader.js:683:19)
ERR     at require (internal/modules/cjs/helpers.js:16:16)
ERR     at Object.<anonymous> (/home/vcap/deps/0/node_modules/mini-css-extract-plugin/dist/index.js:7:16)
ERR     at Module._compile (internal/modules/cjs/loader.js:776:30)
ERR     at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
ERR     at Module.load (internal/modules/cjs/loader.js:643:32)
ERR     at Function.Module._load (internal/modules/cjs/loader.js:556:12)
ERR     at Module.require (internal/modules/cjs/loader.js:683:19) {
ERR   code: 'MODULE_NOT_FOUND',
ERR   requireStack: [
ERR     '/home/vcap/deps/0/node_modules/mini-css-extract-plugin/dist/index.js',
ERR     '/home/vcap/deps/0/node_modules/mini-css-extract-plugin/dist/cjs.js',
ERR     '/home/vcap/deps/0/node_modules/@zeit/next-css/css-loader-config.js',
ERR     '/home/vcap/deps/0/node_modules/@zeit/next-sass/index.js',
ERR     '/home/vcap/app/next.config.js',
ERR     '/home/vcap/deps/0/node_modules/next/dist/next-server/server/config.js',
ERR     '/home/vcap/deps/0/node_modules/next/dist/next-server/server/next-server.js',
ERR     '/home/vcap/deps/0/node_modules/next/dist/server/next.js',
ERR     '/home/vcap/app/routes/next.js',
ERR     '/home/vcap/app/helpers/startServer.js',
ERR     '/home/vcap/app/server.js'
ERR   ]
ERR }

It seems there is an issue with the mini-css-extract-plugin as part of @zeit/next-sass. We’ve been successfully using this plugin for over a year, with different versions of next.js from 6.0 up to 9.2, and a seemingly unrelated commit is now introducing this error that prevents the site from starting.

This was reported previously in the mini-css-extract-plugin repo: https://github.com/webpack-contrib/mini-css-extract-plugin/issues/198

To Reproduce

I know this isn’t helpful, but I’m unable to provide a repository at this time.

Expected behavior

The app should start.

Screenshots

If applicable, add screenshots to help explain your problem.

System information

  • OS: Linux
  • Version of Next.js: 9.2.2, “@zeit/next-sass”: “^1.0.1”,
  • Version of Node.js: 12.6.0

Additional context

Add any other context about the problem here.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 3
  • Comments: 17 (4 by maintainers)

Most upvoted comments

it happens in next 10.0.6 . we need reproduce

I am facing this issue after upgrading to NextJS 10. It only happens in CI env. @robianmcd Were you able to figure out a workaround for this?

Rolling back to next@10.0.3 fixes webpack dependency.