ljharb / es-abstract

ECMAScript spec abstract operations.
MIT License
114 stars 30 forks source link

Usage of has-symbols in GetIntrinsic.js breaks non-node usages of package #59

Closed nvahalik closed 5 years ago

nvahalik commented 5 years ago

In v1.15.0, GetIntrinsic.js started using has-symbols:

https://github.com/ljharb/es-abstract/blob/master/GetIntrinsic.js#L16

When called in a non-node environment, it causes an error since it is referencing global:

Uncaught (in promise): ReferenceError: global is not defined
./node_modules/has-symbols/index.js@http://my-app-here:2024:18
__webpack_require__@http://localhost:8100/runtime.js:84:30
./node_modules/es-abstract/GetIntrinsic.js@http://my-app-here:749:18
__webpack_require__@http://localhost:8100/runtime.js:84:30
./node_modules/es-abstract/es5.js@http://my-app-here:937:20
__webpack_require__@http://localhost:8100/runtime.js:84:30
./node_modules/string.prototype.trim/implementation.js@http://my-app-here:14204:10
__webpack_require__@http://localhost:8100/runtime.js:84:30

I have confirmed that reverting to v1.14.2 fixes the issue.

ljharb commented 5 years ago

global is the node global, and every bundler by default changes this to window for browsers.

Perhaps you've deviated from the default settings by adding node: false to your webpack config?

nvahalik commented 5 years ago

My current use case is with Ionic v4. Angular builds the app just fine and this problem only happens during runtime.

ljharb commented 5 years ago

Building the app "just fine" would include transforming global to window for the browser, like every bundler has done since node has existed. I'm not familiar with Ionic specifically.

nvahalik commented 5 years ago

@ljharb Apparently for Angular CLI this is no longer the case:

https://github.com/angular/angular-cli/issues/9827#issuecomment-369578814

Angular used to provide a shim for global but as of 6.x, it is not anymore.

nvahalik commented 5 years ago

Closing this ticket out since the problem is actually in the has-symbol module.

ljharb commented 5 years ago

Then Angular has chosen to make much of the ecosystem incompatible ¯_(ツ)_/¯