Next.js: Production build fails on 8.1.0

Created on 19 Apr 2019  Â·  5Comments  Â·  Source: vercel/next.js

Bug report

Describe the bug

Since trying to use 8.1.0, I can no longer perform a production build. It seems that during build, Next.js is actually importing and running the code for my pages – not simply trying to compile them. This is impossible to do in a build step, since some of my components depend on some environmental setup performed in our custom server. If that setup isn't performed, then config properties we expect to exist will not have been loaded.

Thus, the build exits with an error that could only occur if it's actually importing my runtime code.

Expected behavior

Next.js should not try to actually execute my app code during build.

System information

  • OS: macOS
  • Version of Next.js: 8.1.0

Most helpful comment

Can confirm that 8.1.1-canary.34 fixes my issue with UnhandledPromiseRejectionWarning: TypeError: Data must be a string or a buffer during production builds.

All 5 comments

I`ve met the same problem only in production, it seems like dynamic srr:false not working.
eventhough I set like this

const Video = dynamic(() => import('./video'), {
  ssr: false,
  loading: () => <Loading />,
})

it still caused error

ReferenceError: window is not defined
    at Object.<anonymous> (/xx/packageA/index.js:1:260)

packageA was imported only at ./videofile.

I'm getting such error on next.[email protected] (caused by using dynamic import):
I logged chunk id, it is 0 (zero)

(node:28924) UnhandledPromiseRejectionWarning: TypeError: Data must be a string or a buffer
at Hash.update (crypto.js:99:16)
at ids.forEach.id (/node_modules/next/dist/build/webpack/plugins/hashed-chunk-ids-plugin.js:30:41)
at Array.forEach ()
at compilation.hooks.beforeChunkIds.tap.chunks (/node_modules/next/dist/build/webpack/plugins/hashed-chunk-ids-plugin.js:30:25)
at SyncHook.eval [as call] (eval at create (/node_modules/tapable/lib/HookCodeFactory.js:19:10), :7: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:33:10), :6:1)
at AsyncSeriesHook.lazyCompileHook (/node_modules/tapable/lib/Hook.js:154:20)
at Compilation.seal (/node_modules/webpack/lib/Compilation.js:1244:27)
(node:28924) 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:28924) [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.
✨ Done in 7.43s.

I'm getting such error on next.[email protected] (caused by using dynamic import):
I logged chunk id, it is 0 (zero)

(node:28924) UnhandledPromiseRejectionWarning: TypeError: Data must be a string or a buffer
at Hash.update (crypto.js:99:16)
at ids.forEach.id (/node_modules/next/dist/build/webpack/plugins/hashed-chunk-ids-plugin.js:30:41)
at Array.forEach ()
at compilation.hooks.beforeChunkIds.tap.chunks (/node_modules/next/dist/build/webpack/plugins/hashed-chunk-ids-plugin.js:30:25)
at SyncHook.eval [as call] (eval at create (/node_modules/tapable/lib/HookCodeFactory.js:19:10), :7: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:33:10), :6:1)
at AsyncSeriesHook.lazyCompileHook (/node_modules/tapable/lib/Hook.js:154:20)
at Compilation.seal (/node_modules/webpack/lib/Compilation.js:1244:27)
(node:28924) 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:28924) [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.
✨ Done in 7.43s.

I removed dynamic import part but I also get this problem; how to resolve it, thanks

Had similar issue with UnhandledPromiseRejectionWarning messages. Not sure which patch fixed it but if you install the latest canary version it seems to run as expected.

Can confirm that 8.1.1-canary.34 fixes my issue with UnhandledPromiseRejectionWarning: TypeError: Data must be a string or a buffer during production builds.

Was this page helpful?
0 / 5 - 0 ratings