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
https://github.com/jpbow/module-register-build-issue
next build success
Tried yarn install --forceand Clean depends install.
next . dev-command work properly.
Please provide a full reproduction
I'll provide reproduction tomorrow. Today I don't have access to my pc.
Close because it's firebase grpc problem.
There is similar problem in #7821
Close because it's firebase grpc problem.
How can i fixed it?
I have same problem
@go-rani Currently I don't have a solution because I not fully sure that this problem belongs to firebase. I trying to reproduce this bug in example project.
I have the same problem. It goes normal when I downgrade to v8
here is the image I am using:
gcr.io/google_appengine/nodejs
@vbilici interesting...
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.
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.
As I understand any dependency with grpc breaking nextjs build?
Getting this issue as well.
I was able to build at first, but it happens when my /pages grown big. I tried reverting back to an old commit where i can build without issue and duplicate my /pages folder (-v1, -v2 and so on) build after build to a point where it fails.
I couldn't quantify how "big" is big but hope this helps.
@timneutkens @Vista1nik I've created a reproduction here https://github.com/jpbow/module-register-build-issue
@jpbow Thanks for repoduction, added to issue.
just chiming in, this also fails when deploying with now 2.0
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.
@Vista1nik it'll fail with both firebase and gcp. Both use grpc.
after updating my next.config.js with the following (as mentioned in #6073 )
webpack(config, options) {
if (process.env.NODE_ENV !== "development") {
config.externals = {
grpc: "grpc"
};
}
return config;
}
link: https://github.com/zeit/next.js/issues/6073#issuecomment-498025104
My deployment error has changed, I don't think this is optimal but may be a temporary workaround for others who are trying to update production builds
the new error seems related to AMP toolbox,
running "yarn run now-build"
Jul 22 2019 14:05:48:345 | ...next.config.js | yarn run v1.16.0
Jul 22 2019 14:05:48:403 | ...next.config.js | $ next build
Jul 22 2019 14:05:49:159 | ...next.config.js | Creating an optimized production build ...
Jul 22 2019 14:05:49:824 | ...next.config.js | > Using external babel configuration
Jul 22 2019 14:05:49:824 | ...next.config.js | > Location: "/tmp/bc0fa1c/babel.config.js"
Jul 22 2019 14:07:52:235 | ...next.config.js | Failed to compile.
Jul 22 2019 14:07:52:235 | ...next.config.js | ./node_modules/amp-toolbox-optimizer/lib/transformers/AddBlurryImagePlaceholders.js
Jul 22 2019 14:07:52:235 | ...next.config.js | Module not found: Can't resolve 'jimp' in '/tmp/bc0fa1c/node_modules/amp-toolbox-optimizer/lib/transformers'
Jul 22 2019 14:07:52:235 | ...next.config.js | Â
which is annoying as I'm not using AMP at all, not sure how related this is but hopefully its helpful.
I am having the same issue using firebase.. Has anyone found a deployment workaround?
For some reason building my project on mac OS _works_, while on Debian I get the same "Module did not self-register" error.
Did anyone found any workaround for this issue?
There must be joke about "Buy new Mac".
Currently only downgrade is solution.
tested and #8290 fixes it. When is the canary release coming that contains it?
Hi @getorca, the fix should be in v9.0.4-canary.3 which is up now
This change has been released as [email protected]. You may upgrade your application(s)!
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
@ebemunk please provide a clear and concise reproduction that we can have a look at. Posting "It doesn't work in my case" is not going to solve your issue.
thanks for looking @timneutkens , apologies i did not provide a reproduction step as the issue is the exact same as the one already reported, and previous reproduction steps are still valid.
here's a minimal example, using https://github.com/jpbow/module-register-build-issue that @jpbow created.
git clone https://github.com/jpbow/module-register-build-issue.git
cd module-register-build-issue
yarn add [email protected]
yarn build
You get the exact same error reproduced i previous comments:
Creating an optimized production build .Automatically opError: Failed to load /xxxxx/module-register-build-issue/node_modules/grpc/src/node/extension_binary/node-v72-darwin-x64-unknown/grpc_node.node. Module did not self-register.
To see the why it is a regression, I did
yarn add [email protected]
yarn build
It succeeds as expected. Trying the version that this issue was fixed:
yarn add [email protected]
yarn build
Succeeds again. Trying a version before this fix landed:
yarn add [email protected]
yarn build
Fails with the same message above.
Critical line seems to be import "firebase/firestore";. If this line is removed then no grpc error is observed.
Hope that helps clarify.
I was also suddenly getting that error after dozens of successful builds, but it seems like updating to 9.0.6 fixed it.
With 9.1.1 and firestore still have this issue.
EDIT: downgrading to 9.0.5
With 9.1.1 and firestore still have this issue.
downgrading to 9.0.4 or 9.0.5 fix it ...
Error occurred prerendering /services: Error: Failed to load /Users/me/myproject/node_modules/grpc/src/node/extension_binary/node-v67-darwin-x64-unknown/grpc_node.node. Module did not self-register.
at Object.Module._extensions..node (internal/modules/cjs/loader.js:775:18)
at Module.load (internal/modules/cjs/loader.js:626:32)
at tryModuleLoad (internal/modules/cjs/loader.js:566:12)
at Function.Module._load (internal/modules/cjs/loader.js:558:3)
at Module.require (internal/modules/cjs/loader.js:663:17)
at require (internal/modules/cjs/helpers.js:20:18)
at Object.<anonymous> (/Users/me/myproject/node_modules/grpc/src/grpc_extension.js:32:13)
at Module._compile (internal/modules/cjs/loader.js:734:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:745:10)
at Module.load (internal/modules/cjs/loader.js:626:32)
This error happened for each pages
fwiw this is not really a Next.js issue. It seems that grpc breaks on specific Node.js versions. I ran into this the other day with node 12 and it works perfectly fine on node 10.
@timneutkens
But what Next use in versions above 9.0.5 that produce the crash ?
I keep the same Node version (11.9.0), I just switch the Next version and get the issue when it's above 9.0.5. I agree that this issue is caused by grpc but could we eventually isolate the link between Next changes in 9.0.6 and grpc to find a workaround ?
But what Next use in versions above 9.0.5 that produce the crash ?
Feel free to investigate what caused the issues.
Work on 9.0.6-canary.0
Crash on 9.0.6-canary.1
I more so meant investigate as in actually figure out the issue 🚀
I did a git bisect and identified https://github.com/zeit/next.js/commit/f81b6d56e03d3f883e8c5faebae44208bd1a328b to be the first commit that breaks next build in conjunction with firebase/grpc.
I assume this is related to https://github.com/grpc/grpc-node/issues/778.
I'd be happy to help on this one however I'm currently a bit lost as to what a proper solution could look like.
Any ideas @ijjk, @Timer, @timneutkens?
I test every patch on 9.0.6-canary.1 and the error happened on : 61b8b73
I will continue to investigate tomorrow but actually I note that on line 117 in worker.js
const components = await loadComponents(
distDir,
buildId,
page,
serverless
)
failed and then
catch (error) {
console.error(\nError occurred prerendering ${path}:, error)
return { ...results, error: true }
} }
@notiles this is interesting. I did a git bisect between v9.0.5 and v9.0.6-canary.1 and found that the first bad commit was https://github.com/zeit/next.js/commit/f81b6d56e03d3f883e8c5faebae44208bd1a328b.
While the commit you are mentioning (https://github.com/zeit/next.js/commit/61b8b7323e089c8cc0372ce0f32402c8d70096f8) is definitely broken for me as well, the commit before that one (https://github.com/zeit/next.js/commit/110c83fa443a7a557a82dc49968dee56e293680c) is also broken for me.
Could you try it with https://github.com/zeit/next.js/commit/f81b6d56e03d3f883e8c5faebae44208bd1a328b and see if that still works for you?
@ctavan Good morning ! On my side f81b6d5 is working, my build succeed.
I find where it crash but I can't go further :
in packages/next/next-server/server/load-components.ts
line 70 : interopDefault(require(appPath)) failed.
appPath look good : /Users/me/myproject/.next/server/static/eUfibox1CSt3iNdo6twQi/pages/_app
@notiles this is really, really weird! What node version and operating system are you using?
Here are detailed steps to reproduce how I can reliably reproduce the issue on my machine. Would you like to try them out as well and let me know if it really builds for you with https://github.com/zeit/next.js/commit/f81b6d56e03d3f883e8c5faebae44208bd1a328b ?
# MacOS 10.14.6 (18G103)
#
node --version
# v12.12.0
# Steps to reproduce:
git clone https://github.com/zeit/next.js.git
cd next.js
# Check out the last working commit:
git checkout 2c7b4d8a
# Build local next module:
yarn
# Demonstrate the issue using the included example:
cd examples/with-firebase-authentication
# Use local next module:
sed -i '' -e "s#\"next\": \"latest\"#\"next\": \"file:$(pwd)/../../packages/next\"#" package.json
# Upgrade firebase modules because the ones defined in package.json won't build
# with node 12:
yarn add [email protected] [email protected]
# Duplicate the single page from the example to provoke a parallel build. The
# issue only appears when multiple pages are built in parallel:
cp pages/index.js pages/parallel.js
# Ensure there's no local installation of next, then force install the example
# and try to build it:
rm -rf node_modules/next && yarn install --force && yarn build
# yarn run v1.19.1
# warning package.json: No license field
# $ next build
# Creating an optimized production build ...
#
# Compiled successfully.
#
# Page Size Files Packages
# ┌ σ / 3.23 kB 1 7
# ├ /_app 1.83 kB 0 7
# ├ /_document
# ├ /_error 7.71 kB 0 7
# └ σ /parallel 3.24 kB 1 7
#
# σ (Server) page will be server rendered (i.e. getInitialProps)
# âš¡ (Static File) page was prerendered as static HTML
#
# ✨ Done in 19.53s.
# Now back to the repository root and checkout the first broken commit:
cd ../../
git checkout f81b6d5
# Build the local next module again:
yarn
# Try to build the example again:
cd examples/with-firebase-authentication
rm -rf node_modules/next && yarn install --force && yarn build
# yarn run v1.19.1
# warning package.json: No license field
# $ next build
# Creating an optimized production build ...
#
# Compiled successfully.
#
# > Build error occurred
# Error: Failed to load /Users/*REDACTED*/next.js/examples/with-firebase-authentication/node_modules/grpc/src/node/extension_binary/node-v72-darwin-x64-unknown/grpc_node.node. Module did not self-register.
# at Object.Module._extensions..node (internal/modules/cjs/loader.js:1003:18)
# at Module.load (internal/modules/cjs/loader.js:812:32)
# at Function.Module._load (internal/modules/cjs/loader.js:724:14)
# at Module.require (internal/modules/cjs/loader.js:849:19)
# at require (internal/modules/cjs/helpers.js:74:18)
# at Object.<anonymous> (/Users/*REDACTED*/next.js/examples/with-firebase-authentication/node_modules/grpc/src/grpc_extension.js:32:13)
# at Module._compile (internal/modules/cjs/loader.js:956:30)
# at Object.Module._extensions..js (internal/modules/cjs/loader.js:973:10)
# at Module.load (internal/modules/cjs/loader.js:812:32)
# at Function.Module._load (internal/modules/cjs/loader.js:724:14) {
# type: 'Error'
# }
# error Command failed with exit code 1.
# info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
I'm also on Mac OS 10.14.6 but I'm on node 11.9.0 I'll try and tell you if I can build
Like you it crash with f81b6d5.
In my project I'm using
"react-redux-firebase": "^2.4.1",
"redux-firestore": "^0.9.0",
"firebase": "^7.1.0",
I update my firebase to 7.2.1 and try with 61b8b73 and build succeed... really weird
Try to remove this import : import "firebase/firestore"; only in index.js
@notiles if you remove one of the two firebase/firestore imports then you are no longer provoking a parallel build of two modules that require grpc.
As mentioned above I'm pretty confident that the issue we are observing here is caused by https://github.com/grpc/grpc-node/issues/778 which states that grpc "Does not support multiple threads".
As a workaround I figured out that builds succeed with the following next.config.js:
module.exports = {
experimental: {
cpus: 1,
},
};
and fail as soon as you increase the CPU count (which further proves that parallel worker execution is the root cause). Obviously builds will then no longer take advantage of multiple worker threads, so this is a workaround, not a solution.
@ijjk, @Timer, @timneutkens sorry for bugging you again: how would you deal with this issue?
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...
I was a bit too quick. With the next.config.js from my previous comment the build did work for https://github.com/zeit/next.js/commit/f81b6d56e03d3f883e8c5faebae44208bd1a328b but not with [email protected] because https://github.com/zeit/next.js/commit/61b8b7323e089c8cc0372ce0f32402c8d70096f8 introduced jest-worker to next export which is called as part of the build step.
My initial idea was to pass the config.experimental.cpus on to the export worker, however I did not succeed. Even with setting numWorkers: 1 the export step in the build will fail with the Module did not self-register. error.
The only way of getting it to work for my use case was setting enableWorkerThreads: false in:
A possible workaround could be to allow setting config.experimental.cpus: 0 and as a consequence disabling worker threads altogether. I will provide a Pull Request for this suggestion shortly.
Ok @ctavan ! That's totally true, I change enableWorkerThreads to false and build succeed with next 9.1.1
So finally it's more a grpc issue than a next issue ? What's your feeling about that ? Do you think that we have to open an issue on grpc ?
Thanks a lots for all your explanations that's really helpfull.
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.
HEY EVERYBODY!
Just Add
"engines": {
"node": "10.x"
}
To your package.json
You are welcome coders.
for anyone else who was tracking this issue:
I can confirm I no longer get "Module did not self-register" when using grpc.
v9.3.2 includes #11347 which is what fixed it
I have the same error
Error: Error occurred while parsing your function triggers.
Error:
Something went wrong installing the "sharp" module
Module did not self-register.
Most helpful comment
I have a feeling that it's caused by newly added build report. Because the error throws after build completes