Skip to content

Outdated buffer sub dependency causes global is not defined error #15954

@ohcibi

Description

@ohcibi

🐞 Bug report

Following #8160 I found that it is still possible to cause the global ist not defined error without installing a library that actively uses global. It is caused by buffer which is a sub dependency of @angular-devkit/build-angular.

Command (mark with an x)

No command. It is a runtime issue. Any command that builds the project obviously.

Is this a regression?

Yes, the regression is obviously the removal of the global shim.

Description

@angular-devkit/build-angular depends on a version of webpack, which depends on a version of node-libs-browser (deprecated!) which depends on a version of buffer that is actually using global.

$ npm ls buffer
iotgen-webui@0.1.0 /Users/ohcibi/Documents/Projekte/PERK/iotgen/iotgen-webui
└─┬@angular-devkit/build-angular@0.803.14
  └─┬ webpack@4.39.2
    └─┬ node-libs-browser@2.2.1
      └── buffer@4.9.1

The latest versions of the buffer package have fixed that but since node-libs-browser is deprecated, this won't fix on webpack4. webpack 5 does not have the node-libs-browser dependency anymore.

The library I have installed and try to import was jwt-simple.

🔬 Minimal Reproduction

npm install -D jwt-simple
# Add `import jwt from 'jwt-simple' to some angular module
ng serve
# Visit route that uses the module with the import and see error in console

🔥 Exception or Error


index.js:43 Uncaught ReferenceError: global is not defined
    at Object../node_modules/buffer/index.js (index.js:43)
    at __webpack_require__ (bootstrap:79)
    at Object../node_modules/safe-buffer/index.js (index.js:2)
    at __webpack_require__ (bootstrap:79)
    at Object../node_modules/randombytes/browser.js (browser.js:15)
    at __webpack_require__ (bootstrap:79)
    at Object../node_modules/crypto-browserify/index.js (index.js:3)
    at __webpack_require__ (bootstrap:79)
    at Object../node_modules/jwt-simple/lib/jwt.js (jwt.js:13)
    at __webpack_require__ (bootstrap:79)

🌍 Your Environment



     _                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / ‚ñ≥ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/
    

Angular CLI: 8.3.12
Node: 12.12.0
OS: darwin x64
Angular: 8.1.3
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.803.14
@angular-devkit/build-angular     0.803.14
@angular-devkit/build-optimizer   0.803.14
@angular-devkit/build-webpack     0.803.14
@angular-devkit/core              8.3.14
@angular-devkit/schematics        8.3.12
@angular/cli                      8.3.12
@ngtools/webpack                  8.3.14
@schematics/angular               8.3.12
@schematics/update                0.803.12
rxjs                              6.4.0
typescript                        3.4.5
webpack                           4.39.2
    


Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions