next.js: `next build` fails with "Module did not self-register."

Bug report

Describe the bug

next build fails with following error after upgrade to Next 9.

{ Error: Module did not self-register.
    at Object.Module._extensions..node (internal/modules/cjs/loader.js:857:18)
    at Module.load (internal/modules/cjs/loader.js:685:32)
    at Function.Module._load (internal/modules/cjs/loader.js:620:12)
    at Module.require (internal/modules/cjs/loader.js:723:19)
    at require (internal/modules/cjs/helpers.js:14:16)
    at Object.<anonymous> (/home/vista1nik/Documents/nextjs-project/node_modules/grpc/src/grpc_extension.js:32:13)
    at Module._compile (internal/modules/cjs/loader.js:816:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:827:10)
    at Module.load (internal/modules/cjs/loader.js:685:32)
    at Function.Module._load (internal/modules/cjs/loader.js:620:12) type: 'Error', '$error': '$error' }

Error happens after compilation. Last Build trigger before error is: https://github.com/zeit/next.js/blob/5a54e8715a7a7a92175addc19f4ec9f8f7bbd2e7/packages/next/build/index.ts#L342

To Reproduce

https://github.com/jpbow/module-register-build-issue

Expected behavior

next build success

System information

  • OS: Arch Linux
  • Version of Next.js: 9.0.0

Additional context

Tried yarn install --forceand Clean depends install.

next . dev-command work properly.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 22
  • Comments: 56 (14 by maintainers)

Commits related to this issue

Most upvoted comments

HEY EVERYBODY! Just Add

“engines”: { “node”: “10.x” }

To your package.json

You are welcome coders.

I have a feeling that it’s caused by newly added build report. Because the error throws after build completes

Creating an optimized production build ...

> Using external babel configuration
> Location: "/app/.babelrc"
Compiled successfully.

Warning: You have opted-out of Automatic Prerendering due to `getInitialProps` in `pages/_app`.
Read more: https://err.sh/next.js/opt-out-automatic-prerendering

> Build error occurred
{ Error: Module did not self-register.
    at Object.Module._extensions..node (internal/modules/cjs/loader.js:730:18)
    at Module.load (internal/modules/cjs/loader.js:600:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
    at Function.Module._load (internal/modules/cjs/loader.js:531:3)
    at Module.require (internal/modules/cjs/loader.js:637:17)
    at require (internal/modules/cjs/helpers.js:22:18)
    at Object.<anonymous> (/app/node_modules/@firebase/firestore/node_modules/grpc/src/grpc_extension.js:32:13)
    at Module._compile (internal/modules/cjs/loader.js:701:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
    at Module.load (internal/modules/cjs/loader.js:600:32) type: 'Error', '$error': '$error' }
error Command failed with exit code 1.

This change has been released as next@9.0.4. You may upgrade your application(s)!

tested and #8290 fixes it. When is the canary release coming that contains it?

I’m having same issue.

But when I comment out ‘import firebase/firestore’, this issue did’nt happen.

import firebase from 'firebase/app';
import 'firebase/auth';
import 'firebase/functions';
import 'firebase/database';
// import 'firebase/firestore'; <-- 

But I need firebase/firestore. this is not solution.

With 9.1.1 and firestore still have this issue.

EDIT: downgrading to 9.0.5

Hi @getorca, the fix should be in v9.0.4-canary.3 which is up now

seems like this regressed in 9.0.6. downgrading to 9.0.5 or 9.0.4 still builds properly. with 9.0.6 i get the same error about grpc

I am having the same issue using firebase… Has anyone found a deployment workaround?

@jpbow Thanks for repoduction, added to issue.

As I understand any dependency with grpc breaking nextjs build?

I have now proposed https://github.com/zeit/next.js/pull/9199 where setting config.experimental.cpus: 1 will disable worker threads altogether. This makes next build succeed for all use cases that involve grpc and that I have tested.

For me, that would be an acceptable workaround until the issue is fixed in grpc or firebase. There is already an issue in the grpc repo (https://github.com/grpc/grpc-node/issues/778) but apparently the solution depends on upstream changes in node (https://github.com/nodejs/nan/issues/844).

I now believe that this is something that rather needs to be fixed in grpc, not here. At least I don’t see a straightforward way of fixing it in Next.js without going back to older parallelization technology which would definitely hurt the codebase.

If https://github.com/zeit/next.js/pull/9199 gets accepted we would at least have a way to build projects that depend on firebase/firestore, even though build times might be longer since we cannot make use of parallelism.

It’s clear @ctavan ! Thanks a lot for this explanation. Unfortunately I still have the issue with experimental: { cpus: 1, }

`Warning: You have enabled experimental feature(s). Experimental features are not covered by semver, and may cause unexpected or broken application behavior. Use them at your own risk.

Using external babel configuration Location: “/Users/me/myproject/.babelrc” Creating an optimized production build

Compiled successfully.

Automatically optimizing pages … Error occurred prerendering /download/[document_id]: Error: Failed to load /Users/me/myproject/node_modules/grpc/src/node/extension_binary/node-v72-darwin-x64-unknown/grpc_node.node. Module did not self-register.

etc…`

I switch form Node 11.9.0 to Node 10.12 and Node 13.0.1 to Node 12.13.0 without success…

For some reason building my project on mac OS works, while on Debian I get the same “Module did not self-register” error.

It’s seems like NextJS 9 is incompatible with dependencies which use GRPC in anyway. Currently I trying to find any other package which use GRPC to confirm that.

just chiming in, this also fails when deploying with now 2.0