3
votes

I've got the same issue like here: Why webpack bundled as 'System.register'

I've build bundle.js with webpack and I am getting error:

Uncaught ReferenceError: System is not defined

my bundle.js inlcudes:

   System.register(['angular2/platform/browser', './app.component', 'rxjs/Rx'], function(exports_1, context_1) {
        "use strict";
        var __moduleName = context_1 && context_1.id;
        var browser_1, app_component_1;
        return {
            setters:[
                function (browser_1_1) {
                    browser_1 = browser_1_1;
                },
                function (app_component_1_1) {
                    app_component_1 = app_component_1_1;
                },
                function (_1) {}],
            execute: function() {
                //enableProdMode();
                browser_1.bootstrap(app_component_1.AppComponent)
                    .then(function (success) { return console.log("Bootstrap success"); })
                    .catch(function (error) { return console.log(error); });
            }
        }
    });

I've already changed module to commonjs in tsconfig.json, so it's probably some silly mistake somewhere. Here is my tsconfig.json

{
  "compilerOptions": {
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es5",
    "module": "commonjs",
    "removeComments": true,
    "sourceMap": false
  },
  "exclude": [
      "node_modules"
  ]
}

and webpack.config.js

module.exports = {
  entry: "./app/main",
  output: {
    filename: "bundle.js"
  },
  resolve: {
    extensions: ['', '.js', '.ts']
  },
  module: {
    loaders: [{
      test: /\.ts/, loaders: ['ts-loader'], exclude: /node_modules/
    }]
  }
};

Thanks for any help

2
the same issue for me - avagrkjllkjfdser3
have you resolved this problem? - avagrkjllkjfdser3
Yes I've fixed, like I thought in my case it was a small silly mistake, my IDE was automaticaly (on save) compiling ts files to js, so webpack, on build was also adding this js files to the bundle so it was causing issues. - creativedeveloper.net

2 Answers

1
votes

Change module to commonjs in compilerOptions of your tsconfig.json.

0
votes

When using webpack with Typescript project, the .ts files should not be transpiled to .js files if you are using commonjs as a module.