angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

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

Open sinedied opened this issue 9 years ago β€’ 62 comments

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]

sinedied avatar Nov 05 '17 15:11 sinedied

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

sinedied avatar Nov 07 '17 14:11 sinedied

mm

npm -v
5.5.1

Ismaestro avatar Nov 07 '17 14:11 Ismaestro

@sinedied can you provide us a repo??

Ismaestro avatar Nov 07 '17 14:11 Ismaestro

@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

sinedied avatar Nov 07 '17 15:11 sinedied

screen shot 2017-11-07 at 16 19 53

Ismaestro avatar Nov 07 '17 15:11 Ismaestro

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 :)

Ismaestro avatar Nov 07 '17 15:11 Ismaestro

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

sinedied avatar Nov 07 '17 15:11 sinedied

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

GiuseppePiscopo avatar Nov 07 '17 16:11 GiuseppePiscopo

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

rsaulo avatar Nov 08 '17 00:11 rsaulo

@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 avatar Nov 08 '17 08:11 dimitriy-k

@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.

rsaulo avatar Nov 08 '17 12:11 rsaulo

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 avatar Nov 09 '17 20:11 KthProg

@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.

dhasilva avatar Nov 09 '17 20:11 dhasilva

The beta version fixed the issue for me.

KthProg avatar Nov 09 '17 20:11 KthProg

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

clydin avatar Nov 09 '17 20:11 clydin

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

Splaktar avatar Nov 09 '17 21:11 Splaktar

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

KthProg avatar Nov 09 '17 21:11 KthProg

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 avatar Nov 09 '17 21:11 KthProg

@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.

GiuseppePiscopo avatar Nov 10 '17 14:11 GiuseppePiscopo

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

Stradivario avatar Nov 13 '17 23:11 Stradivario