Since upgrading my version of next from 8.0.4 to 8.1, the next build command no longer works and the following is outputted:
"(node:1055) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): TypeError [ERR_INVALID_ARG_TYPE]: The "original" argument must be of type function
(node:1055) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code."
Can confirm that this is a new bug, as downgrading next version back to 8.0.4 resolves the issue. The issue is not only present in my apps, but also the examples.
/examples/custom-server.npm i.next run build.And you'll end up with the above error.
A production-optimised build of the app is generated.
Tested on custom-server-express example
OS: Windows
No problem
I have the ~same~ problem. What is your node version @LoicVerrall? I'm running v11.10.0.
Edit:
Actually my error is different, but the outcome is the same:
$ yarn build
yarn run v1.15.2
$ rimraf .next && next build
Creating an optimized production build ...
[00:08:47] Compiling client
[00:08:47] Compiling server
> Using external babel configuration
> Location: "/.../.babelrc"
(node:46139) UnhandledPromiseRejectionWarning: TypeError [ERR_INVALID_ARG_TYPE]: The "data" argument must be one of type string, Buffer, TypedArray, or DataView. Received type number
at Hash.update (internal/crypto/hash.js:64:11)
at ids.forEach.id (/.../node_modules/next/dist/build/webpack/plugins/hashed-chunk-ids-plugin.js:24:41)
at Array.forEach (<anonymous>)
at compilation.hooks.beforeChunkIds.tap.chunks (/.../node_modules/next/dist/build/webpack/plugins/hashed-chunk-ids-plugin.js:24:25)
at SyncHook.eval [as call] (eval at create (/.../node_modules/tapable/lib/HookCodeFactory.js:19:10), <anonymous>:12:1)
at SyncHook.lazyCompileHook (/.../node_modules/tapable/lib/Hook.js:154:20)
at hooks.optimizeTree.callAsync.err (/.../node_modules/webpack/lib/Compilation.js:1275:30)
at AsyncSeriesHook.eval [as callAsync] (eval at create (/.../node_modules/tapable/lib/HookCodeFactory.js:32:10), <anonymous>:9:1)
at AsyncSeriesHook.lazyCompileHook (/.../node_modules/tapable/lib/Hook.js:154:20)
at Compilation.seal (/.../node_modules/webpack/lib/Compilation.js:1244:27)
(node:46139) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:46139) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
[00:09:06] Compiled server in 19s
✨ Done in 21.83s.
Hm, just tried building, starting and also running dev for examples/custom-server and examples/custom-server-express and they both work..
Ah, so I was running node v8.1.4. Updating to v12.0.0 resolves the issue so I'll close this issue.
Thanks for the help @stovmascript!
I also tried node v12.0.0, but with that I get something even wilder:
$ yarn build
yarn run v1.15.2
$ rimraf .next && next build
Creating an optimized production build ...
#
# Fatal error in , line 0
# Check failed: U_SUCCESS(status).
#
#
#
#FailureMessage Object: 0x7ffeefbf2e00/bin/sh: line 1: 14501 Illegal instruction: 4 next build
error Command failed with exit code 132.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
It seems to have been introduced in this version: https://github.com/zeit/next.js/releases/tag/v8.0.5-canary.12
Do you get that error on the example projects as well?
If so, perhaps you could try using npm instead of yarn to isolate the cause a little further?
Well the problem in the error I posted seems to be a bad value being passed into the .update() method of createHash from crypto here:
In my case the array of ids sometimes contains a number (2), which trips up this method expecting a string or a buffer, etc.
@Timer Converting the id to a string to be hashed works, but I have no idea if that will have any unintended side effects. I can submit a PR should this be an ok fix, tests are passing.
@stovmascript if you delete .next/records.json (or entire .next) does this still reproduce?
shouldn't you use the stable version of node v10.15.3 it's the one that I used
@Timer I'm actually already doing that, my build script is rimraf .next && next build.
@MarchWorks I also tested on v10.10.0, but no go.
I think the examples are working because they don't generate chunks that have ids which are just numbers.
@stovmascript converting the ID to a string isn't the correct fix -- this is a webpack bug.
Can you please share a reproducible demo with me so we can fix the root cause? The module IDs _must_ be computed -- having an numerical module ID isn't going to work soon.
Thought so.
Currently it's happening on a private project, so can't share that, but
I'll try to derive a new demo from that somehow.
@stovmascript actually, can you hand edit your node_modules/next/dist/build/webpack-config.js and find this line:
!dev && selectivePageBuilding && new AllModulesIdentifiedPlugin(dir)
and change it to:
!dev && new AllModulesIdentifiedPlugin(dir)
And report back if that fixes it?
Thanks!
@Timer Yup, that does it.
Also dumps some stuff into the console, along the lines of:
> module identifier: MultiModule multi private-next-pages/_app.js => 1TCz
> module identifier: MultiModule multi private-next-pages/_document.js => 5w0S
> module identifier: MultiModule multi private-next-pages/_error.js => Y0NT
Excellent @stovmascript, can you send a PR removing that switch from the plugin? 🙏
Ran into same exact error on nextjs v8.1.0.
Was only happening on a new page I created.
Issue:
I was importing a server-side only node module that's incompatible with webpack.
Resolution:
import the module only when nextjs is running server-side.
ie.
static getInitialProps() {
if (!process.browser) {
const server_side_module = require('path_to_module');
}
}
Most helpful comment
I have the ~same~ problem. What is your node version @LoicVerrall? I'm running v11.10.0.
Edit:
Actually my error is different, but the outcome is the same: