Next.js: corejs2 with worker-loader _ Uncaught ReferenceError: window is not defined

Created on 23 Jul 2019  路  7Comments  路  Source: vercel/next.js

Bug report

Describe the bug

worker-loader load some worker file, but Uncaught ReferenceError window is not defined, see the Screenshots.

To Reproduce

Steps to reproduce the behavior, please provide code snippets or a repository:

use this project and update the next.js version to lastest.
("next": "^8.1.0",) is OK.

https://github.com/ritz078/transform

Expected behavior

Screenshots

Jietu20190723-153015

System information

  • OS: macOS
  • Browser chrome
  • Version of Next.js: 9.0.2

Additional context

Add any other context about the problem here.

bug needs investigation

Most helpful comment

This was fixed.

All 7 comments

Specific reproduction https://github.com/ritz078/transform/pull/126

I was talking about this with @developit yesterday.

Figured out that https://github.com/zeit/next.js/blob/v9.0.2/packages/next/build/webpack-config.ts#L469 breaks it currently. I'll see if we can override it in a certain way.

This is caused by childCompiler copying all plugins, which makes it include the typeof window replacement. To add on top of this the hooks (webpack hooks, not React hooks) are copied over to the childCompiler, meaning that we can't just detect the childCompiler and remove / conditionally add it only when not in childCompiler because of this.

Even solving for the plugin copying issue, webpack/webpack#2979 means DefinePlugin definitions will always be enforced in child compilers :(

@timneutkens I thought of a possible solution here: use babel-plugin-transform-replace-expressions instead of DefinePlugin, since we can do so separately for each compilation. It would also have the pleasant side effect of only applying this optimization (cull client code from server, server code from client) to first-party authored code.

This was fixed.

How to resolve this issue? @timneutkens

Was this page helpful?
0 / 5 - 0 ratings

Related issues

formula349 picture formula349  路  3Comments

kenji4569 picture kenji4569  路  3Comments

wagerfield picture wagerfield  路  3Comments

ghost picture ghost  路  3Comments

timneutkens picture timneutkens  路  3Comments