Angular-cli: Uncaught ReferenceError: req is not defined with [email protected]

Created on 5 Nov 2017  Â·  62Comments  Â·  Source: angular/angular-cli

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 [email protected]

Most helpful comment

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

All 62 comments

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

This is actually a bug in uglify-es and looks like the next version should have a fix.
Relevant issue: https://github.com/mishoo/UglifyJS2/issues/2437

Upgrading node.js to latest LTS version, re-installing [email protected] & upgrading typescript to 2.6.1 I got rid this anoying error after rebuild my project. Before this, I got unmeet peer dependency on typescript & other angular dependencies.

I got the same error here when upgrading a Angular 4.XX project to use with Angular-CLI 1.5

What's the workaround here? :)

Same error when upgrade to Angular 5.0.0 and Angular-CLI 1.5

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.

I have the same problem

Same here. Upgraded from 4.4 to 5

same issue cli 1.5, angular 5

Same here, using Angular 5 and CLI 1.5

Same!!!

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

I also get this error with Angular CLI 1.5.0 :/

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

Yeah, it's definitely a CLI error since reverting to 1.4.9 fixed the problem.

@bh86 that works but waiting for an official fix

Hoping it'd be fixed soon

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.

I want to know how my app will be affected by this bug because it seem still work correctly. And do we have a work around for this issue?

@sandangel Taken straight from @bh86

Works but is super ugly.

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

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

I encountered this error too, in CLI version 1.5 and Angular 5.0

same here

Just for completeness, a production build with sourcemaps enabled shows the following stacktrace:

zone.js:2620 â–¼ Uncaught ReferenceError: req is not defined
    at zone.js:2620
    at zone.js:2543
    at zone.js:2867
    at Function.r.__load_patch (zone.js:86)
    at zone.js:2866
    at c (zone.js:9)
    at Object.<anonymous> (zone.js:8)
    at Object.eFQL (zone.js:3014)
    at n (bootstrap 62f4ccd68d66309f4fdd:54)
    at Object.TU+8 (polyfills.ts:56)
(anonymous) @ zone.js:2620
(anonymous) @ zone.js:2543
(anonymous) @ zone.js:2867
r.__load_patch @ zone.js:86
(anonymous) @ zone.js:2866
c @ zone.js:9
(anonymous) @ zone.js:8
eFQL @ zone.js:3014
n @ bootstrap 62f4ccd68d66309f4fdd:54
TU+8 @ polyfills.ts:56
n @ bootstrap 62f4ccd68d66309f4fdd:54
1 @ reflect.js:15
n @ bootstrap 62f4ccd68d66309f4fdd:54
window.webpackJsonp @ bootstrap 62f4ccd68d66309f4fdd:25
(anonymous) @ polyfills.bundle.js:1

Same here, got this after upgrading to @angular/cli to 1.5.0

upgrade to cli 1.6-beta.0 fix this

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.

I am also facing this since yesterday when I upgraded to cli1.5!

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

@Dasiim Ok will try this. Thanks @clydin !

@VishalGulati please update if it works! Thanks!

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

After remove node_modules same here, still falling

It's a problem with uglify. If you have an ejected webpack config add this to your uglify plugin else it's a wait for the update it seems

uglifyOptions: {
  compress: {
    collapse_vars: false
  }
}

It worked here after removing node_modules. Am I missing something? The problem was happening before the new uglify-es

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

rm -rf node_modules
rm package-lock.json
npm cache clean --force
npm install
ng serve --prod

Still not working with angular@5 / [email protected].

Working here.

With yarn, it worked but not with [email protected], even after clearing cache (see my previous comments) 😞

mm

npm -v
5.5.1

@sinedied can you provide us a repo??

@Ismaestro sure: https://github.com/ngx-rocket/starter-kit/tree/feature/angular5 (make sure to use the feature/angular5 branch)

Here is the full ng --version log:

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

@angular/cli: 1.5.0
@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.1
typescript: 2.4.2
webpack: 3.8.1

screen shot 2017-11-07 at 16 19 53

Avoiding that error (I modified your environment.prod.ts) it works perfectly:
screen shot 2017-11-07 at 16 24 38

Steps I've made:
Clone your repo.
Checkout the feature/angular5 branch.
npm i
ng serve --prod
:)

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 ^^

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:

| | +-- [email protected]
| | | +-- [email protected]
| | | `-- [email protected]
| | |   `-- [email protected]
| | +-- [email protected]
| | | `-- [email protected]
| | `-- [email protected]

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

HTH

Same problem no Linux, same project on Mac works, anyone with this error on Linux?

@rsaulo, I had the same issue on Linux Ubuntu, but now it is solved. So, try to clean the cache or use the latest version of nodejs LTS (8.9.0)

@dimitriy-k it worked only when I updated the cli to 1.6.0. linux was not the problem, the problem only appear when running with --prod flag.

How do I install cli 1.6? It isn't recognized in NPM. No other solutions have worked for me, my issue is also only with --prod flag and upgrading uglify-es does not work.

EDIT: Never mind, finally found it (@angular/[email protected])

@KthProg npm install -g @angular/cli@next
But have in mind that it is still in beta.

EDIT: Deleting node_modules and package-lock.json solved the issue for me.

The beta version fixed the issue for me.

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

Yes, the beta is not required to pick up this fix.

Then why did installing the latest version of uglify-es not work?

Ah you know what, maybe because I had angular cli locally and globally installed (it warned me it would use the local version). That's all I can think of.

@KthProg yep. Uninstall and install globally. Then also uninstall and install locally to your project, so that uglify-es as well gets updated as a by-product.

Installed typescript 2.6.1, removed package-lock.json then npm install again fixed error.

So is the solution to upgrade to the angular/cli to 1.6 and above? Since it contains the updated uglify plugins?

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

_This action has been performed automatically by a bot._

Was this page helpful?
0 / 5 - 0 ratings

Related issues

slubowsky picture slubowsky  Â·  107Comments

DennisSmolek picture DennisSmolek  Â·  110Comments

ankeshdave picture ankeshdave  Â·  161Comments

hansl picture hansl  Â·  163Comments

DanielStep picture DanielStep  Â·  184Comments