next.js: Can no longer build with `9.3.4`

Bug report

Describe the bug

After upgrading to 9.3.4, next build errors with:

❯ npm run build

> my-project@1.0.0 build /dev/my-project
> cross-env NEXT_TELEMETRY_DISABLED=1 next build

Creating an optimized production build  

Failed to compile.

./node_modules/next/dist/client/next.js
TypeError: invalid options argument
    at new Promise (<anonymous>)
    at Generator.throw (<anonymous>)


> Build error occurred
Error: > Build failed because of webpack errors
    at build (/dev/my-project/node_modules/next/dist/build/index.js:13:900)

I noticed that, for some reason, the actual line in which the error is thrown varies between runs of next build, seemingly at random. However, the error message is always the same.

For example:

Failed to compile.

./node_modules/next/dist/client/polyfills.js
TypeError: invalid options argument
Failed to compile.

./node_modules/next/dist/client/router.js
TypeError: invalid options argument

Expected behavior

Project builds correctly.

System information

  • OS: macOS Catalina 10.15.4 (19E266)
  • Version of Next.js: 9.3.4
  • Version of node: v12.16.1

Additional context

No other modifications were done or applied. All other dependencies remain the same in lockfile.

Reverting back to 9.3.3 solves the issue for me.

❯ npm remove next && npm i next@9.3.3

+ next@9.3.3
added 656 packages from 270 contributors and audited 1063442 packages in 27.174s

77 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities

❯ npm run build

> my-project@1.0.0 build /dev/my-project
> cross-env NEXT_TELEMETRY_DISABLED=1 next build

Creating an optimized production build  

Compiled successfully.

Automatically optimizing pages  


# ...

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 17
  • Comments: 43 (18 by maintainers)

Most upvoted comments

@timneutkens I believe I tracked down the issue to the mkdirp dependency. Specifically, how npm’s registry resolves the mkdirp dependency to this repo, while the yarn registry resolves mkdirp dependency to this repo. Swapping out the npm registry version (v1.0.3) for the yarn locked registry version (v0.5.4) seems to have fixed the issue.

Perhaps providing a package.lock.json in addition to the yarn.lock may solve this problem or perhaps adding mkdirp@0.5.4 to next’s package.json devDependencies. Let me know how you wish to proceed. I can create a pull request if needed.

Working example (use npm i or yarn, both should compile without errors): https://github.com/mattcarlotta/next-9.3.4-reproduction

It appears, in andrew’s case, that the apollo package requires mkdir: "^1.0.3", while every other package, requires mkdirp "^0.5.0": T7yQa5F

I do face the same problem with 9.3.4 but with different error message, see below. Version 9.3.3 do me just fine.

> next build

Warning: Built-in CSS support is being disabled due to custom CSS configuration being detected.
See here for more info: https://err.sh/next.js/built-in-css-disabled

Creating an optimized production build  

Failed to compile.

./src/pages/login.js
Error: Cannot find module 'find-cache-dir'


> Build error occurred
Error: > Build failed because of webpack errors
    at build ([XXXXXXXXXX]/node_modules/next/dist/build/index.js:13:900)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! my-app@1.0.15 build: `next build`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the my-app@1.0.15 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     [XXXXXXXX]/.npm/_logs/2020-04-02T11_52_50_720Z-debug.log
Error: > Build failed because of webpack errors
  at build ([XXXXXXXXXX]/node_modules/next/dist/build/index.js:13:900)

^ This part precisely same as @howks @nfantone problem above

Figured out what’s going on, sending a PR to fix

Don’t know why but

  1. delete package-lock.json,
  2. delete node_modules,
  3. and then npm install

seems fix the thing. I successfully run next build after that.

One thing that you could potentially do is this: https://github.com/zeit/next.js/issues/11583#issuecomment-607825557

rm -rf node_modules
rm package-lock.json
rm yarn.lock # this is not used by npm, but just to ensure consistency in CI
npm install

That would clean up your node_modules which could be in a bad state (because of that issue with the npm cli).

I’m not sure why none of these comments provide a complete reproduction which makes it impossible for us to help you / investigate the issue. If you do provide a complete reproduction we can more easily tell you what the problem is.

I’d be super happy to investigate deeper.

https://github.com/andrewl913/next-9.3.4-reproduction here is a reproduction. Not tracking package.lock.json.

Edit: Some further insight, this could related to the intergration with Apollo.

Hi, I also have error after upgrading to 9.3.4

> next build

> Using external babel configuration
Creating an optimized production build

Failed to compile.

./node_modules/next/dist/client/polyfills.js
TypeError: invalid options argument
    at new Promise (<anonymous>)
    at Generator.throw (<anonymous>)


> Build error occurred
Error: > Build failed because of webpack errors
    at build (/node_modules/next/dist/build/index.js:13:900)
npm ERR! code ELIFECYCLE
npm ERR! errno 1

On version 9.3.3 everything works

Please, correct me if I’m wrong here - but I don’t believe that’s the case. Lockfiles are always ignored on npm publish.

That’s what I meant. Reworded my comment a bit.

Here is what I did… When installing next there was a warning :

npm WARN deprecated mkdirp@0.5.4: Legacy versions of mkdirp are no longer supported. Please update to mkdirp 1.x. (Note that the API surface has changed to use Promises in 1.x.)

It was about promises…hmmm ok… It wanted me to upgrade to next9.3.4 to fix this when running npm audit.

I tried to update the mkdirp package but got the same error on running next dev.

I uninstall next and rolled back my next version to @9.3.1

next dev compiled…

@nfantone if you have a chance, clone my repo and see if you still see the issue.

@andrewl913 FWIW, I’m not using GraphQL at all.

I can confirm this is an issue. Wonder how this could get through CI / CD.

This happens with next dev as well