Skip to content

Uncaught ReferenceError: require is not defined #2099

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
nadirowski opened this issue Sep 14, 2016 · 4 comments
Closed

Uncaught ReferenceError: require is not defined #2099

nadirowski opened this issue Sep 14, 2016 · 4 comments
Labels
needs: more info Reporter must clarify the issue

Comments

@nadirowski
Copy link

nadirowski commented Sep 14, 2016

Please provide us with the following information:

  1. OS?
    Windows 10.
  2. Versions.
    angular-cli: 1.0.0-beta.11-webpack.8
    node: 6.3.1
    os: win32 x64
  3. Repro steps. Was this an app that wasn't created using the CLI? What change did you
    do on your code? etc.
    Migrated application from previous angular-cli to angular-cli@webpack,
    Migrated application from angular2-rc4 to angular-rc5
  4. The log given by the failure. Normally this include a stack trace and some
    more information.

VM627:11Uncaught ReferenceError: require is not defined(anonymous function) @ VM627:11e.exports @ scripts.4c654bc….bundle.js:1460 @ scripts.4c654bc….bundle.js:1__webpack_require__ @ inline.js:1888 @ scripts.4c654bc….bundle.js:1__webpack_require__ @ inline.js:1window.webpackJsonp @ inline.js:1(anonymous function) @ scripts.4c654bc….bundle.js:1

  1. Mention any other details that might be useful.

I'm trying to create a production bundle that will be served by nginx by doingng build --env=tst --target=production
Development environment working fine when using ng serve

Snippet from my package.json

 "scripts": {
    "start": "ng serve",
    "lint": "tslint \"src/**/*.ts\"",
    "test": "ng test",
    "pree2e": "webdriver-manager update",
    "e2e": "protractor"
  },

Thanks! We'll be in touch soon.

@filipesilva
Copy link
Contributor

Can you try migrating your apps following the newer instructions? https://github.com/angular/angular-cli#webpack-update

@filipesilva filipesilva added the needs: more info Reporter must clarify the issue label Sep 21, 2016
@nadirowski
Copy link
Author

I still get the same problem in the log but suprisingly, the app works correctly...
Strange.

@nponiros
Copy link

nponiros commented Sep 29, 2016

From what I understand the angular2-template-loader (a webpack loader) replaces the templateUrl/stylesUrl with template/styles using require to load the needed file. You will notice there is no .css/.html in the build directory other than index.html. Since the TypeScript compiler does not know "require" you get that error.

An easy fix is to install types for node via npm install --save-dev @types/node

Also if protractor is installed the issue does not appear as protractor depends on @types/node.

@angular-automatic-lock-bot
Copy link

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.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
needs: more info Reporter must clarify the issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants