Uncaught ReferenceError: req is not defined with [email protected]
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.
- Clone this repo: https://github.com/ngx-rocket/starter-kit
npm installnpm run start -- --prodorng 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]
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

Avoiding that error (I modified your environment.prod.ts) it works perfectly:

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.