Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable worker_threads by default for firebase compatibility #9199

Merged
merged 11 commits into from
Oct 29, 2019
9 changes: 9 additions & 0 deletions examples/with-firebase-authentication/next.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Parallel builds are currently broken due to a limitation in grpc (a transitive firebase
// dependency). Until this is fixed, a workaround is to set the number of available CPUs to 1.
// https://github.com/zeit/next.js/issues/7894
// https://github.com/grpc/grpc-node/issues/778
module.exports = {
experimental: {
cpus: 1
ijjk marked this conversation as resolved.
Show resolved Hide resolved
}
}
3 changes: 2 additions & 1 deletion packages/next/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ export default async function build(dir: string, conf = null): Promise<void> {

const staticCheckWorkers = new Worker(staticCheckWorker, {
numWorkers: config.experimental.cpus,
enableWorkerThreads: true,
enableWorkerThreads: config.experimental.workerThreads,
})

const analysisBegin = process.hrtime()
Expand Down Expand Up @@ -471,6 +471,7 @@ export default async function build(dir: string, conf = null): Promise<void> {
sprPages,
silent: true,
buildExport: true,
threads: config.experimental.cpus,
pages: combinedPages,
outdir: path.join(distDir, 'export'),
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ export default class TaskRunner {

if (this.maxConcurrentWorkers > 1) {
this.workers = new Worker(worker, {
enableWorkerThreads: true,
numWorkers: this.maxConcurrentWorkers,
enableWorkerThreads: true,
})
this.boundWorkers = options => this.workers.default(options)
} else {
Expand Down
2 changes: 1 addition & 1 deletion packages/next/export/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ export default async function(
{
maxRetries: 0,
numWorkers: threads,
enableWorkerThreads: true,
enableWorkerThreads: nextConfig.experimental.workerThreads,
exposedMethods: ['default'],
}
) as any
Expand Down
1 change: 1 addition & 0 deletions packages/next/next-server/server/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const defaultConfig: { [key: string]: any } = {
publicDirectory: false,
sprFlushToDisk: true,
deferScripts: false,
workerThreads: true,
},
future: {
excludeDefaultMomentLocales: false,
Expand Down
2 changes: 2 additions & 0 deletions test/integration/firebase-grpc/pages/page-1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import 'firebase/firestore'
export default () => <div>Firebase</div>
2 changes: 2 additions & 0 deletions test/integration/firebase-grpc/pages/page-2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import 'firebase/firestore'
export default () => <div>Firebase</div>
33 changes: 33 additions & 0 deletions test/integration/firebase-grpc/test/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/* eslint-env jest */
/* global jasmine */
import path from 'path'
import fs from 'fs-extra'
import { nextBuild } from 'next-test-utils'

jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 1
const appDir = path.join(__dirname, '..')
const nextConfig = path.join(appDir, 'next.config.js')

describe('Builds with firebase dependency only sequentially', () => {
it('Throws an error when building with firebase dependency with worker_threads', async () => {
await fs.remove(nextConfig)
const results = await nextBuild(appDir, [], { stdout: true, stderr: true })
expect(results.stdout + results.stderr).toMatch(/Build error occurred/)
expect(results.stdout + results.stderr).toMatch(
/grpc_node\.node\. Module did not self-register\./
)
})

it('Throws no error when building with firebase dependency without worker_threads', async () => {
await fs.writeFile(
nextConfig,
`module.exports = { experimental: { workerThreads: false } }`
)
const results = await nextBuild(appDir, [], { stdout: true, stderr: true })
await fs.remove(nextConfig)
expect(results.stdout + results.stderr).not.toMatch(/Build error occurred/)
expect(results.stdout + results.stderr).not.toMatch(
/grpc_node\.node\. Module did not self-register\./
)
})
})