es-shims / globalThis

ECMAScript spec-compliant polyfill/shim for `globalThis`.
https://github.com/tc39/proposal-global
MIT License
155 stars 14 forks source link

How add to Angular Universal project running in node 10 Firebase function? #16

Closed chrisoppedal closed 3 years ago

chrisoppedal commented 3 years ago

I tried the implementation in the documentation in my polyfill.ts but I'm still getting the error: globalThis is not defined. The polyfill.ts file didn't like using the require keyword so I implemented it like the other Angular polyfills: import 'globalthis/polyfill';

Is there a separate implementation for Angular 11 apps running in node 10?

ljharb commented 3 years ago

If you’re importing it without a binding, you need to import globalthis/auto. The /polyfill entrypoint is a function that if you don’t use, it does nothing.

chrisoppedal commented 3 years ago

Hey thanks for the response. I'm still getting this error in the logs for my firebase 'ssr' function:

Provided module can't be loaded. Is there a syntax error in your code? Detailed stack trace: ReferenceError: globalThis is not defined at Object. (/workspace/dist/test/server/main.js:1:1537696)

My Angular Universal app was deploying fine before adding AngularFire(https://stackoverflow.com/questions/65243054/cant-update-firebase-function-to-node-12-in-angular-universal-app-with-angularf). This is my polyfill.ts file:

import 'zone.js/dist/zone'; // Included with Angular CLI. import 'globalthis/auto';

ljharb commented 3 years ago

You'll want to import globalThis first, since it's a polyfill; beyond that, i'm not sure why it wouldn't be working.

chrisoppedal commented 3 years ago

I was importing it in polyfill.st. To get it to deploy in the firebase node environment I added the following to server.ts: import 'globalthis/auto';