Angular-cli: Cannot find name 'require'.

Created on 1 Nov 2016  路  3Comments  路  Source: angular/angular-cli

OS?

Windows 7, 8 or 10. Linux (which distribution). Mac OSX (Yosemite? El Capitan?)

openSUSE 13.2

Versions.

Please run ng --version. If there's nothing outputted, please run in a Terminal: node --version and paste the result here:

angular-cli: 1.0.0-beta.19-3
node: 6.6.0
os: linux x64

Repro steps.

Was this an app that wasn't created using the CLI? What change did you do on your code? etc.

Locally, the build works correctly; but, Heroku throws the error below, unless I add:

src/typings.d.ts:
declare var require: NodeRequire;

The log given by the failure.

Normally this include a stack trace and some more information.

On Heroku, the ng build -prod fails:

 94% asset optimizationError in bail mode: [default] /tmp/build_47b0228d68fca7157f36b354e7868841/src/app/account/account-list.component.ts:13:12
remote:        Cannot find name 'require'.
remote:        
remote:        npm ERR! Linux 3.13.0-100-generic
remote:        npm ERR! argv "/tmp/build_47b0228d68fca7157f36b354e7868841/.heroku/node/bin/node" "/tmp/build_47b0228d68fca7157f36b354e7868841/.heroku/node/bin/npm" "install" "--unsafe-perm" "--userconfig" "/tmp/build_47b0228d68fca7157f36b354e7868841/.npmrc"
remote:        npm ERR! node v6.6.0
remote:        npm ERR! npm  v3.10.8
remote:        npm ERR! code ELIFECYCLE
remote:        npm ERR! [email protected] postinstall: `ng build -prod`
remote:        npm ERR! Exit status 1

Mention any other details that might be useful.

See #2221 which seems similar/same.

  "dependencies": {
    "@angular/common": "~2.0.0",
    "@angular/compiler": "~2.0.0",
    "@angular/core": "~2.0.0",
    "@angular/forms": "~2.0.0",
    "@angular/http": "~2.0.0",
    "@angular/material": "2.0.0-alpha.9-3",
    "@angular/platform-browser": "~2.0.0",
    "@angular/platform-browser-dynamic": "~2.0.0",
    "@angular/router": "~3.0.0",
    "angular-cli": "1.0.0-beta.19-3",
    "core-js": "^2.4.1",
    "rxjs": "5.0.0-beta.12",
    "ts-helpers": "^1.1.1",
    "zone.js": "^0.6.23",
    "hammerjs": "2.0.8"
  },
  "devDependencies": {
    "@types/jasmine": "^2.2.30",
    "@types/node": "6.0.46",
    "codelyzer": "1.0.0-beta.1",
    "jasmine-core": "2.4.1",
    "jasmine-spec-reporter": "2.5.0",
    "karma": "1.2.0",
    "karma-chrome-launcher": "^2.0.0",
    "karma-cli": "^1.0.1",
    "karma-jasmine": "^1.0.2",
    "karma-remap-istanbul": "^0.2.1",
    "protractor": "4.0.9",
    "ts-node": "1.2.1",
    "tslint": "3.13.0",
    "typescript": "~2.0.3",
    "webdriver-manager": "10.2.5"
  }

Most helpful comment

npm install @types/node --save

Adding "@types/node": "6.0.46" to dependencies instead of devDependencies addresses the compilation problem on Heroku -- now added SO:

http://stackoverflow.com/questions/40365666/heroku-deploy-error-cannot-find-name-require/40365667#40365667

All 3 comments

npm install @types/node --save

Adding "@types/node": "6.0.46" to dependencies instead of devDependencies addresses the compilation problem on Heroku -- now added SO:

http://stackoverflow.com/questions/40365666/heroku-deploy-error-cannot-find-name-require/40365667#40365667

@JanStureNielsen Sorry, but just one question, adding this as a dependency and not dev dependency, will this mean when hosting in IIS, this functionality wont work?

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