0

After doing some initial Angular 2 quick starts and Todos, I am trying to put up an initial structure with some simple build scripts for my next step. But now I am stuck at this error. I had been trying different solutions provided in similar questions asked here, for past couple of days, but my problem is still unresolved.

angular2-polyfills.js:1243 Error: ReferenceError: require is not defined
    at eval (http://localhost:3000/app/app.js:11:14)
    at eval (http://localhost:3000/app/app.js:42:3)
    at Zone.run (http://localhost:3000/angular2/bundles/angular2-polyfills.js:1243:24)
Evaluating http://localhost:3000/app/app.js
Error loading http://localhost:3000/app/app.js as "./app/app" from http://localhost:3000/main.js

Zone.run @ angular2-polyfills.js:1243
zoneBoundFn @ angular2-polyfills.js:1220
lib$es6$promise$$internal$$tryCatch @ angular2-polyfills.js:468
lib$es6$promise$$internal$$invokeCallback @ angular2-polyfills.js:480
lib$es6$promise$$internal$$publish @ angular2-polyfills.js:451
lib$es6$promise$$internal$$publishRejection @ angular2-polyfills.js:401
(anonymous function) @ angular2-polyfills.js:123Zone.run @ angular2-polyfills.js:1243
zoneBoundFn @ angular2-polyfills.js:1220
lib$es6$promise$asap$$flush @ angular2-polyfills.js:262

Here you can find the broken version of my code at GitHub.

Any help is much appreciated.

Thanks.

M.D.
  • 1,886
  • 1
  • 13
  • 14
  • Change `"module": "commonjs"` to `"module": "system"` in your tsconfig.json – Eric Martinez Mar 17 '16 at 02:39
  • 1
    As soon as I change "commonjs" to "system", I get lots of compile errors as below: src\app\app.ts(4,31): error TS2307: Cannot find module 'angular2/core'. src\app\app.ts(5,60): error TS2307: Cannot find module 'angular2/router'. .......... src\main.ts(4,25): error TS2307: Cannot find module 'angular2/platform/browser'. src\main.ts(5,23): error TS2307: Cannot find module 'angular2/core'. src\main.ts(6,32): error TS2307: Cannot find module 'angular2/http'. src\main.ts(7,74): error TS2307: Cannot find module 'angular2/router'. – M.D. Mar 17 '16 at 02:49
  • 1
    Add `moduleResolution : node` and upgrade your TS version, you're on 1.5.3, the recommended is >= 1.8.0 – Eric Martinez Mar 17 '16 at 02:51
  • Thank you Eric. It worked with your suggested solutions. If you can post it as Answer, I will accept it. One more thing, Can you point me to a page where I can read about commonjs and system and which one to use... when/why? – M.D. Mar 17 '16 at 03:37

0 Answers0