Leon Gaban Leon Gaban - 1 year ago 2585
Javascript Question

Angular2 5 minute install bug - require is not defined

I'm doing the Angular2 5 minute quick start.

About half way through the tutorial now, I have the following files setup correctly:

  • index.html,

  • app.component.ts

  • app/boot.ts

  • package.json

  • tconfig.json

npm start
and am getting this error:

Uncaught ReferenceError: require is not defined(anonymous function) @ boot.js:1
Uncaught TypeError: Cannot read property 'split' of undefinedreadMemberExpression @ system.src.js:1456(anonymous function) @ system.src.js:3224(anonymous function) @ system.src.js:3749complete @ system.src.js:2487run @ angular2-polyfills.js:138zoneBoundFn @ angular2-polyfills.js:111

I found this link about using the es6 shim and I included
<script src="node_modules/es6-shim/es6-shim.js"></script>

However I'm still getting the
Uncaught ReferenceError: require is not defined


import {Component} from 'angular2/core';

selector: 'my-app',
template: '<h1>My First Angular 2 App</h1>'
export class AppComponent { }


import {bootstrap} from 'angular2/platform/browser'
import {AppComponent} from './app.component'




<title>Angular 2 QuickStart</title>

<!-- 1. Load libraries -->
<script src="node_modules/es6-shim/es6-shim.js"></script>
<script src="node_modules/angular2/bundles/angular2-polyfills.js"></script>
<script src="node_modules/systemjs/dist/system.src.js"></script>
<script src="node_modules/rxjs/bundles/Rx.js"></script>
<script src="node_modules/angular2/bundles/angular2.dev.js"></script>

<!-- 2. Configure SystemJS -->
packages: {
app: {
format: 'register',
defaultExtension: 'js'
.then(null, console.error.bind(console));


<!-- 3. Display the application -->



"name": "angular2-quickstart",
"version": "1.0.0",
"scripts": {
"tsc": "tsc",
"tsc:w": "tsc -w",
"lite": "lite-server",
"start": "concurrent \"npm run tsc:w\" \"npm run lite\" "
"license": "ISC",
"dependencies": {
"angular2": "2.0.0-beta.0",
"systemjs": "0.19.6",
"es6-promise": "^3.0.2",
"es6-shim": "^0.33.3",
"reflect-metadata": "0.1.2",
"rxjs": "5.0.0-beta.0",
"zone.js": "0.5.10"
"devDependencies": {
"concurrently": "^1.0.0",
"lite-server": "^1.3.1",
"typescript": "^1.7.3"


"compilerOptions": {
"target": "ES5",
"module": "system",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": false
"exclude": [

The compiled app/boot.js

enter image description here

Last log from
npm start

enter image description here


OK finally got my 'basic' app to work.

First my problem was that npm start was not compiling my typescript .ts files.

From this post, I found an answer here Cannot find external module 'angular2/angular2' - Angular2 w/ Typescript

I needed to run npm install -g tsd@latest to update my TypeScript definition. Right after that I needed to update the TypeScript Definition (TSD) for Angular2 tsd install angular2.

After this was done I was still getting errors from my boot.js file.

Instead of this import {AppComponent} from './app.component'

I needed to write it like this import {AppComponent} from '../app.component.js'

Now it works! https://github.com/leongaban/angular2quickstart

enter image description here

One annoying problem is that npm start still isn't auto compiling the typescript files, so I still have to manually compile each .ts file by hand tsc app.component.ts --module system