Next.js: `global` not set in browser from webpack for `2.x-beta`

Created on 23 Dec 2016  路  15Comments  路  Source: vercel/next.js

Example repo showing a reference to MobX which assumes global is window in the browser.
https://github.com/philcockfield/nextjs-mobx

To start run:

npm run dev

Error is thrown when MobX attempts to initialize itself by looking at global:

image

The failing line of code: https://github.com/mobxjs/mobx/blob/6e3df706de1f1fc2408ba919559297cd0d07573e/src/core/globalstate.ts#L91

bug

All 15 comments

cc @arunoda

Did this work with next 1.x?

Yes, it works on 1.2.3.

Getting the same error with uuid.
image

If I remove all my uuid references then it throws the same thing with React

image

Found this thread https://github.com/webpack/webpack/issues/1963

Looks like this problem will get automatically get fixed when webpack 2 support is added via https://github.com/zeit/next.js/pull/449

EDIT: Seems like it's not.

@nkzawa is this because we removed the use of babel-plugin-transform-remove-strict-mode?

@philcockfield frankly I don't know how this was not an issue in next 1.x and but in 2.x.
I just tried with #449 and seems like it's fixed in that.

is this because we removed the use of babel-plugin-transform-remove-strict-mode?

@arunoda probably

@arunoda, @nkzawa - awesome re #449 - and getting Webpack 2 rolling. That blocking issue seems like it's progressing, but ominous! Any chance a webpack 2 enabled beta of Nextjs will be released soon?

I get the same issue when using uuid dependency, worked in [email protected] but with [email protected] I get Cannot read property 'crypto' of undefined, apparently thrown here (looking for global.crypto). /cc @luisrudge

Seems like we need to fix global :D

Guys, I did a fix for this and it's now available on the master.
Could you try it out?

@arunoda I still get the error after tried on branch master

screen shot 2016-12-26 at 9 04 11 pm

I checked with @philcockfield's example repo and it works pretty well.
@hoangzinh could you send us a sample app as well?

@arunoda I tested on 2.0.0-beta.5, it works property on my repo right now. Thanks @arunoda

Was this page helpful?
0 / 5 - 0 ratings