angular-cli: Uncaught ReferenceError: req is not defined with cli@1.5

Bug Report or Feature Request (mark with an x)

- [x] bug report -> please search issues before submitting
- [ ] feature request

Versions.

Angular CLI: 1.5.0
Node: 7.9.0
OS: darwin x64
Angular: 4.4.6
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router, tsc-wrapped

@angular/cdk: 2.0.0-beta.12
@angular/cli: 1.5.0
@angular/flex-layout: 2.0.0-beta.9
@angular/material: 2.0.0-beta.12
@angular/service-worker: 1.0.0-beta.16
@angular-devkit/build-optimizer: 0.0.32
@angular-devkit/core: 0.0.20
@angular-devkit/schematics: 0.0.35
@ngtools/json-schema: 1.1.0
@ngtools/webpack: 1.8.0
@schematics/angular: 0.1.0
typescript: 2.4.2
webpack: 3.8.1

Repro steps.

  1. Clone this repo: https://github.com/ngx-rocket/starter-kit
  2. npm install
  3. npm run start -- --prod or ng serve --prod

The log given by the failure.

Build is successful, but app is throwing an error that seems to be due to zone.js polyfill:

polyfills.5ae6b10132b7e8411589.bundle.js:1 Uncaught ReferenceError: req is not defined
    at polyfills.5ae6b10132b7e8411589.bundle.js:1
    at polyfills.5ae6b10132b7e8411589.bundle.js:1
    at polyfills.5ae6b10132b7e8411589.bundle.js:1
    at Function.r.__load_patch (polyfills.5ae6b10132b7e8411589.bundle.js:1)
    at polyfills.5ae6b10132b7e8411589.bundle.js:1
    at u (polyfills.5ae6b10132b7e8411589.bundle.js:1)
    at Object.<anonymous> (polyfills.5ae6b10132b7e8411589.bundle.js:1)
    at Object.eFQL (polyfills.5ae6b10132b7e8411589.bundle.js:1)
    at n (inline.f05f710f0631368b608c.bundle.js:1)
    at Object.TU+8 (polyfills.5ae6b10132b7e8411589.bundle.js:1)

Desired functionality.

App does not throw any error.

Mention any other details that might be useful.

Was working fine with angular-cli@1.4

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 49
  • Comments: 62 (11 by maintainers)

Commits related to this issue

Most upvoted comments

We did the following (ugliest) workaround, in index.html: <script> window.req = window.dep = null; </script>

Webpack’s uglifyjs plugin was updated in CLI 1.5 which replaced uglify-js with uglify-es. This currently has a bug in its collapse_var optimization which is the cause of the error.

Just tested after a rm -rf node_modules, I still got the error.

Yes. It looks like a fix is in place and should be in the next patch version of uglify (3.1.8).

Solved! I removed node_modules folder AND package-lock.json and now it works!

uglify-es 3.1.8 is out with the fix. There’s no need to update the CLI just ensure that version 3.1.8 or greater of uglify-es is installed.

It seems to be an CLI problem, Angular 4.4.6 and CLI 1.5 got the error

Angular 4.4.6 and CLI 1.4.9 everything works fine

As stated by @clydin, reinstall node_modules and it should be fixed 😃

I am also getting this but not using cli directly just the new AngularCompilerPlugin. Seems the app still functions though.

Note that what that did was just force uglify-es to be reinstalled since it’s a dependency of the CLI.

For me it was enough to look in node_modules for top level uglify-related packages, then reinstall them locally:

# uninstall
npm un uglify-js
npm un uglify-to-browserify
npm un uglifyjs-webpack-plugin

# install
npm i

At the end of the process, npm i output confirmed that the latest uglify-es version was installed as a transitive dependency:

| | +-- find-cache-dir@1.0.0
| | | +-- commondir@1.0.1
| | | `-- make-dir@1.1.0
| | |   `-- pify@3.0.0
| | +-- uglify-es@3.1.8
| | | `-- source-map@0.6.1
| | `-- worker-farm@1.5.1

Also, for this project there was no package-lock.json file to delete.

HTH

It finally worked after a new batch of remove, cache clean and install again 🙄 I suspect I hit a cache somewhere (as yarn was fine), but anyways it’s solved so I close the issue.

Thanks @Ismaestro for confirming that the problem was on my side ^^

With yarn, it worked but not with npm@5.5.1, even after clearing cache (see my previous comments) 😞

upgrade to cli 1.6-beta.0 fix this

the issue identified by @clydin in uglify-es seems to be marked as solved now https://github.com/mishoo/UglifyJS2/issues/2437

I updated from the latest 5 RC to the final 5 version. After that I got this error and “Cannot read property ‘subscribe’ of undefined” for some routes which made it impossible to navigate to this routes.

Even downgrading to the latest 5RC did not work which might be happening because of some dependency which has no pinned version and the latest one is broken.

Only a downgrade to the latest Angular 4 did make it work again.

Btw: On Thursday I updated another project and there were no problems.