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

Indirect dependency on Node environment #150

Open
kamsar opened this issue Jun 29, 2018 · 3 comments
Open

Indirect dependency on Node environment #150

kamsar opened this issue Jun 29, 2018 · 3 comments

Comments

@kamsar
Copy link

kamsar commented Jun 29, 2018

I'm using url-parse within an Angular 6 (angular-cli) app.

Within url-parse, there's a place where it's looking for global, which does not exist in a browser environment:

var location = global && global.location || {};

In Angular 6 CLI, they removed webpack features that added a shim for global in a browser environment: angular/angular-cli#9827

When url-parse runs in the browser without the shim, I get ERROR ReferenceError: global is not defined

If I manually add a shim, for example <script>window.global = {};</script> in the head, it works.

It seems like a simple addition of a definition check for global would fix it longer term, such as:

typeof global !== 'undefined' && global.location || {};
@3rd-Eden
Copy link
Member

Is this not fixed by #136 ?

@kamsar
Copy link
Author

kamsar commented Jun 29, 2018

It's not fixed by #136 (url-parse 1.4.1) for me.

If I run this in the Chrome console, it works (mimicking the test):

var foo = undefined; foo && foo.bar || {}
// {}

But if I run this, without setting foo to undefined, it breaks:

bar && bar.baz || {}
// Uncaught ReferenceError: bar is not defined

And this works:

typeof bar !== 'undefined' && bar.baz || {}
// {}

@mattslocum
Copy link

I just had the same problem. It seems that the url-parse/index.js doesn't define global. If you import the UMD, it works even though it is hacky to not import the main directly:
import * as urlParse from 'url-parse/dist/url-parse';

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

No branches or pull requests

3 participants