2

I have been developing an angular 2 application which i downloaded from angular2 quickstart application. When I run and build the application it shows require is not defined.

Uncaught ReferenceError: require is not defined

Below is the code how i am including system.js

//index.html
<!DOCTYPE html>
<html>
 <head>
   <title>Angular QuickStart</title>
   <meta charset="UTF-8">
   <meta name="viewport" content="width=device-width, initial-scale=1">
   <link rel="stylesheet" href="app/styles/main.css">

   <!-- Polyfill(s) for older browsers -->
   <script src="node_modules/core-js/client/shim.min.js"></script>
   <script src="node_modules/zone.js/dist/zone.js"></script>
   <script src="node_modules/reflect-metadata/Reflect.js"></script>
   <script src="node_modules/systemjs/dist/system.src.js"></script>

   <script src="systemjs.config.js"></script>
   <script>
     System.import('app').catch(function(err){ console.error(err); });
   </script>
2
  • are you trying to build with commonjs and try to importit Commented Oct 7, 2016 at 19:21
  • yes, commin js is used while building Commented Oct 7, 2016 at 19:24

1 Answer 1

2

This happens when you try to build with commonjs and try to load with systemjs loader. In you tsconfig.json change the module to system.

my tsconfig.json below.

{
  "compilerOptions": {
    "target": "es5",
    "module": "system",
    "moduleResolution": "node",
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "removeComments": false,
    "noImplicitAny": true,
    "suppressImplicitAnyIndexErrors": true

  }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.