Skip to content

ReferenceError: global is not defined - Intl polyfill #9920

Closed
@MattMorrisDev

Description

@MattMorrisDev

Versions

Angular CLI: 6.0.0-beta.5
Node: 8.9.0
OS: darwin x64
Angular: 6.0.0-beta.7
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

@angular/cdk: 6.0.0-beta.4
@angular/cli: 6.0.0-beta.5
@angular/material: 6.0.0-beta.4
@angular-devkit/build-optimizer: 0.4.5
@angular-devkit/core: 0.4.5
@angular-devkit/schematics: 0.4.5
@ngtools/json-schema: 1.2.0
@ngtools/webpack: 6.0.0-beta.5
@schematics/angular: 0.4.5
@schematics/package-update: 0.4.5
typescript: 2.6.2
webpack-bundle-analyzer: 2.10.0
webpack: 4.0.1

(Side note: the issue template says to use ng --version, but that was removed in a recent version and wasn't mentioned as a breaking change :))

Repro steps

  • I'm importing the following in polyfills.ts:
    import 'intl';
    import 'intl/locale-data/jsonp/en';

Observed behavior

On app startup, I see the following error:

index.js:2 Uncaught ReferenceError: global is not defined
    at eval (index.js:2)
    at Object../node_modules/intl/index.js (polyfills.js:2880)
    at __webpack_require__ (runtime.js:75)
    at eval (polyfills.ts:36)
    at Object../src/polyfills.ts (polyfills.js:2926)
    at __webpack_require__ (runtime.js:75)
    at Object.1 (polyfills.js:2937)
    at __webpack_require__ (runtime.js:75)
    at checkDeferredModules (runtime.js:44)
    at Array.webpackJsonpCallback [as push] (runtime.js:31)

where index.js is the following:

// Expose `IntlPolyfill` as global to add locale data into runtime later on.
global.IntlPolyfill = require('./lib/core.js');

// Require all locale data for `Intl`. This module will be
// ignored when bundling for the browser with Browserify/Webpack.
require('./locale-data/complete.js');

// hack to export the polyfill as global Intl if needed
if (!global.Intl) {
    global.Intl = global.IntlPolyfill;
    global.IntlPolyfill.__applyLocaleSensitivePrototypes();
}

// providing an idiomatic api for the nodejs version of this module
module.exports = global.IntlPolyfill;

It doesn't crash the application, although the browser I'm using doesn't need the polyfill. But I wouldn't expect to see this error normally.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions