Reputation: 61
I have set up an angular 2 app with mvc. I am using typescript 2.3.1.0 for visual studio. I installed the node modules and added reference to angular 2.
Views -> Home -> Index file -
@{
ViewBag.Title = "Home Page";
}
<div class="jumbotron">
<h1>Angular 2 QuickStart</h1>
</div>
<div class="row">
<div class="col-md-4">
<!-- Angular2 Code -->
<my-app>Loading...</my-app>
<!-- Angular2 Code -->
</div>
</div>
And I added all the references to my Views -> Shared -> Layout file -
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="google-signin-client_id" content="118134028665-i6h833e7irrrhk0n52bgj7ve6fet4vgr.apps.googleusercontent.com">
<title>@ViewBag.Title - My ASP.NET Application</title>
@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")
<!-- Angular2 Code -->
<base href="/">
<link rel="stylesheet" href="styles.css">
<!-- Polyfill(s) for older browsers -->
<script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=Intl.~locale.en"></script>
<script src="https://code.angularjs.org/tools/system.js"></script>
<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>
<!-- Angular2 Code -->
</head>
<body>
<script src="~/Scripts/jquery-1.10.2.min.js" type="text/javascript"></script>
<script src="~/JS/SocialLogin.js" type="text/javascript"></script>
<script src="https://apis.google.com/js/platform.js" async defer></script>
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="navbar-header">
</div>
<div class="navbar-collapse collapse">
</div>
</div>
</div>
<div class="container body-content">
@RenderBody()
<hr />
<footer>
<p>© @DateTime.Now.Year - My ASP.NET Application</p>
</footer>
</div>
@Scripts.Render("~/bundles/bootstrap")
@RenderSection("scripts", required: false)
</body>
</html>
This is my package.json file -
{
"name": "angular-quickstart",
"version": "1.0.0",
"scripts": {
"start": "tsc && concurrently \"npm run tsc:w\" \"npm run lite\" ",
"lite": "lite-server",
"postinstall": "typings install",
"tsc": "tsc",
"tsc:w": "tsc -w",
"typings": "typings"
},
"license": "ISC",
"dependencies": {
"@angular/common": "2.0.0",
"@angular/compiler": "2.0.0",
"@angular/core": "2.0.0",
"@angular/forms": "2.0.0",
"@angular/http": "2.0.0",
"@angular/platform-browser": "2.0.0",
"@angular/platform-browser-dynamic": "2.0.0",
"@angular/router": "3.0.0",
"@angular/upgrade": "2.0.0",
"core-js": "^2.4.1",
"reflect-metadata": "^0.1.3",
"rxjs": "5.0.0-beta.12",
"systemjs": "0.19.27",
"zone.js": "^0.6.23",
"angular2-in-memory-web-api": "0.0.20",
"bootstrap": "^3.3.6"
},
"devDependencies": {
"concurrently": "^2.2.0",
"lite-server": "^2.2.2",
"typescript": "^2.0.2",
"typings":"^1.3.2"
}
}
This is my systemjs.config.js file -
(function (global) {
System.config({
paths: {
// paths serve as alias
'npm:': 'node_modules/'
},
// map tells the System loader where to look for things
map: {
// our app is within the app folder
app: 'app',
// angular bundles
'@angular/core': 'npm:@angular/core/bundles/core.umd.js',
'@angular/common': 'npm:@angular/common/bundles/common.umd.js',
'@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.js',
'@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.js',
'@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',
'@angular/http': 'npm:@angular/http/bundles/http.umd.js',
'@angular/router': 'npm:@angular/router/bundles/router.umd.js',
'@angular/forms': 'npm:@angular/forms/bundles/forms.umd.js',
// other libraries
'rxjs': 'npm:rxjs',
'angular-in-memory-web-api': 'npm:angular-in-memory-web-api',
},
// packages tells the System loader how to load when no filename and/or no extension
packages: {
app: {
main: './main.js',
defaultExtension: 'js'
},
rxjs: {
defaultExtension: 'js'
},
'angular-in-memory-web-api': {
main: './index.js',
defaultExtension: 'js'
}
}
});
})(this);
When the node modules folder is not included in the project, it is build successfully and when I run it is working ok.
Once I publish it and move the publish to a dev server and deploy it on IIS the mvc runs but the angular 2 is not. These are the errors that I get -
I assume that I get this errors since the node modules folder is missing.
If I go back to the project and include node modules in the project and build it I get these errors -
Severity Code Description Project File Line Suppression State Error Build:File 'E:/MyApp/MyApp/MyApp.Site/node_modules/browser-sync/node_modules/rx/ts/core/linq/observable/mergeproto.ts' not found. MyApp.Site E:\MyApp\MyApp\MyApp.Site\tsc
Severity Code Description Project File Line Suppression State Error Build:File 'E:/MyApp/MyApp/MyApp.Site/node_modules/browser-sync/node_modules/rx/ts/core/linq/observable/zipproto.ts' not found. MyApp.Site E:\MyApp\MyApp\MyApp.Site\tsc
How can I solve this issue? What is the correct way to deploy angular 2 app with .net mvc on iis? What is the right way to include the node modules in this project?
Thanks!
Upvotes: 4
Views: 852
Reputation: 47
I have also faced same issue and didn't got appropriate solution , So i have used another solution.
ng prod
. If you get any error ping me.
Upvotes: 1