【发布时间】:2017-05-15 18:12:02
【问题描述】:
我正在开发一个新的 ASP.Net Core 项目,我已经 followed a blog post 使用 Angular 2 和 Type Script 设置它。一旦我将 Type Script 文件添加到我的项目中,我的 xproj 文件中就会出现以下构建错误。
我做错了什么吗?这是我的 project.json、package.json 和 systemjs.config.js 以及项目中唯一的 Type Script 文件。
project.json
{
"title": "Manage Care Web",
"userSecretsId": "ManageCare-Apps-Web-c23d27a4-eb88-4b18-9b77-2a93f3b15119",
"dependencies": {
"Microsoft.AspNetCore.Razor.Tools": {
"version": "1.0.0-preview2-final",
"type": "build"
},
"Microsoft.Extensions.Configuration": "1.1.0",
"Microsoft.Extensions.Configuration.EnvironmentVariables": "1.1.0",
"Microsoft.Extensions.Configuration.Json": "1.1.0",
"Microsoft.Extensions.Configuration.UserSecrets": "1.1.0",
"Microsoft.Extensions.Logging": "1.1.0",
"Microsoft.Extensions.Logging.Console": "1.1.0",
"Microsoft.Extensions.Logging.Debug": "1.1.0",
"Microsoft.Extensions.Options.ConfigurationExtensions": "1.1.0",
"Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.1.0",
"BundlerMinifier.Core": "2.2.306",
"Microsoft.ApplicationInsights.AspNetCore": "1.0.2",
"Microsoft.AspNetCore.Diagnostics": "1.1.0",
"Microsoft.AspNetCore.Identity": "1.1.0",
"Microsoft.AspNetCore.Mvc": "1.1.0",
"Microsoft.AspNetCore.Server.IISIntegration": "1.1.0",
"Microsoft.AspNetCore.StaticFiles": "1.1.0",
"Microsoft.NETCore.App": "1.1.0",
"Microsoft.AspNetCore.Server.Kestrel": "1.1.0",
"AspNet.Security.OAuth.Validation": "1.0.0-alpha2-final",
"OpenIddict": "1.0.0-*",
"OpenIddict.EntityFrameworkCore": "1.0.0-*",
"OpenIddict.Mvc": "1.0.0-*",
"Security.AspIdentity": "1.0.0-*",
"Microsoft.AspNetCore.Authentication.JwtBearer": "1.0.0",
"Security.Jwt": "1.0.0-*"
},
"tools": {
"Microsoft.AspNetCore.Razor.Tools": "1.0.0-preview2-final",
"Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final",
"Microsoft.Extensions.SecretManager.Tools": "1.0.0-preview2-final"
},
"frameworks": {
"netcoreapp1.0": {
"dependencies": {
"DataAccess.Abstraction": {
"target": "project"
},
"DataAccess.SqlServer": {
"target": "project"
},
"Domain.Provider": {
"target": "project"
},
"Domain.Security": {
"target": "project"
},
"Security.Abstractions": {
"target": "project"
},
"Services.Abstractions": {
"target": "project"
},
"Services.Provider": {
"target": "project"
}
},
"imports": [
"dotnet5.6",
"portable-net45+win8"
]
}
},
"buildOptions": {
"emitEntryPoint": true,
"preserveCompilationContext": true
},
"runtimeOptions": {
"configProperties": {
"System.GC.Server": true
}
},
"runtimes": {
"win10-x64": {},
"win7-x64": {}
},
"publishOptions": {
"include": [
"wwwroot",
"Views",
"Areas/**/Views",
"appsettings.json",
"web.config"
]
},
"scripts": {
"prepublish": [ "bower install", "dotnet bundle" ],
"postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
}
}
package.json
{
"version": "1.0.0",
"name": "managecare",
"private": true,
"scripts": {
"postinstall": "typings install",
"tsc": "tsc",
"tsc:w": "tsc -w",
"typings": "typings"
},
"dependencies": {
"@angular/common": "^2.4.1",
"@angular/compiler": "^2.4.1",
"@angular/core": "^2.4.1",
"@angular/forms": "^2.4.1",
"@angular/http": "^2.4.1",
"@angular/platform-browser": "^2.4.1",
"@angular/platform-browser-dynamic": "^2.4.1",
"@angular/router": "^3.4.1",
"core-js": "^2.4.1",
"jquery": "^3.1.1",
"reflect-metadata": "^0.1.9",
"rxjs": "^5.0.2",
"systemjs": "^0.19.41",
"zone.js": "^0.7.4"
},
"devDependencies": {
"concurrently": "3.0.0",
"gulp": "^3.9.1",
"gulp-cssmin": "0.1.7",
"gulp-uglify": "2.0.0",
"gulp-concat": "2.6.1",
"rimraf": "2.5.4",
"typescript": "2.0.3",
"typings": "1.4.0"
}
}
systemjs.config.js
/**
* System configuration for Angular samples
* Adjust as necessary for your application needs.
*/
(function (global) {
System.config({
paths: {
// paths serve as alias
'npm:': 'libs/'
},
// 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',
},
// packages tells the System loader how to load when no filename and/or no extension
packages: {
app: {
main: './ClientApp.js',
defaultExtension: 'js'
},
rxjs: {
defaultExtension: 'js'
}
}
});
})(this);
typings.config
{
"globalDependencies": {
"core-js": "registry:dt/core-js#0.0.0+20160725163759",
"jasmine": "registry:dt/jasmine#2.2.0+20160621224255",
"node": "registry:dt/node#6.0.0+20160909174046"
}
}
tsconfig.json
{
"compileOnSave": true,
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": false
},
"exclude": [
"node_modules"
]
}
ClientApp.ts
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
// import { AppModule } from './App/app.module';
const platform = platformBrowserDynamic();
// platform.bootstrapModule(AppModule);
这个设置我做错了什么?我以前从未使用过 Type Script,但我的印象是这在 Visual Studio 中是开箱即用的。除了我链接到的博客文章中描述的内容之外,我还需要做更多的事情吗?
更新
我按照匿名用户的建议安装了 Typings npm 包,但是当我运行 typings install dt~core-js --global --save 时出现以下异常。
C:\Users\Sully\AppData\Roaming\npm\node_modules\typings\node_modules\typings-core\node_modules\strip-bom\index.js:2 模块.exports = x => { ^^
SyntaxError: Unexpected token => 在exports.runInThisContext (vm.js:73:16) 在 Module._compile (module.js:443:25) 在 Object.Module._extensions..js (module.js:478:10) 在 Module.load (module.js:355:32) 在 Function.Module._load (module.js:310:12) 在 Module.require (module.js:365:17) 在需要(module.js:384:17) 在对象。 >
(C:\Users\Sully\AppData\Roaming\npm\node_modules\typings\node_modules\typings-core\dist\utils\fs.js:5:16) 在 Module._compile (module.js:460:26) 在 Object.Module._extensions..js (module.js:478:10)
【问题讨论】:
标签: asp.net angularjs typescript