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

fix(env): don't assume process is defined #692

Closed
wants to merge 3 commits into from
Closed

Conversation

Haroenv
Copy link
Contributor

@Haroenv Haroenv commented May 5, 2018

Summary

Most environments (webpack, browserify) by default define process as a shim for it.

However, some environements don't supply it, so we should always guard against it not being defined

fixes #691

(should be tested in a real angular app first)

Result

guards around every use of process

Most environments (webpack, browserify) by default define `process` as a shim for it.

However, some environements don't supply it, so we should always guard against it not being defined

fixes #691

(should be tested in a real angular app first)
@Haroenv
Copy link
Contributor Author

Haroenv commented May 7, 2018

shoot, this somehow makes browserify add an extra polyfill for process in the bundle 😡

@@ -10,7 +10,9 @@ var store = require('./store.js');
// proxies limit)
var MAX_API_KEY_LENGTH = 500;
var RESET_APP_DATA_TIMER =
process.env.RESET_APP_DATA_TIMER && parseInt(process.env.RESET_APP_DATA_TIMER, 10) ||
(typeof process !== 'undefined' &&
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is actually only needed in integration tests and could be turned into a hidden option (__resetAppDataTimer)

@vvo
Copy link

vvo commented May 15, 2018

Can we make it so that the fix is inside Angular InstantSearch?
The one you proposed @Haroenv, can we ship it inside Angular InstantSearch?

(window as any).process = {
  env: { DEBUG: undefined },
};

I am trying to find "the good way" to fix this in the community, as using process.env is common I am not sure of the right way to rewrite it.

@Haroenv
Copy link
Contributor Author

Haroenv commented May 15, 2018

That could be an option, I’ll try that out

@iam4x
Copy link

iam4x commented May 17, 2018

I've tried to hotfix this into Angular InstantSearch directly with:

// HOTFIX: define process
if (typeof window !== "undefined") {
  (window as any).process = { env: {} };
} else if (typeof global !== "undefined") {
  (global as any).process = { env: {} };
}

As entry point before anything else, it does not work :/

@Haroenv
Copy link
Contributor Author

Haroenv commented Jun 5, 2018

Since the workaround works in user land and this is stalled on the fact that it adds an additional process polyfill in the bundles, I'll close this. We can revisit later, especially #692 (comment) can probably be done regardless

@Haroenv Haroenv closed this Jun 5, 2018
@Haroenv Haroenv deleted the fix/guard-process branch June 5, 2018 15:23
@keichinger
Copy link

@Haroenv can we maybe re-open this issue as it still breaks any Webpack web-only build for those people that don't want to ship extra polyfills or shims?

This fix would not only improve some broken builds right now but is also necessary if you want to support Webpack 5, as it'll get rid of node polyfills (see https://twitter.com/wSokra/status/1076126619146899462).

It seemed like a good idea for now but like a necessity for the future, IMO :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Angular 6 Uncaught ReferenceError: process is not defined
4 participants