Jos*_*e A 8 typescript asp.net-core-mvc visual-studio-2015 angular
首先:我检查过这些:
https://github.com/angular/angular/issues/7052
https://github.com/angular/angular/issues/4902
尽管使用ECMAScript 6,却打字稿找不到名字'Promise'
如何摆脱Angular2/TypeScript错误无法找到地图,承诺...当定位-es5时
还有很多很多.现在已经敲了两天头.
是的:
我在我的boot.ts文件(或引导程序文件)中引用了:
///<reference path="../node_modules/angular2/typings/browser.d.ts"/>
Run Code Online (Sandbox Code Playgroud)
现在,问题是:我正在使用Visual Studio 2015 W/Update 1和ASP.NET MVC 6项目(Release Candidate 1)+ Typescript 1.8.1.
我使用本教程进行设置:http: //www.mithunvp.com/angular-2-in-asp-net-5-typescript-visual-studio-2015/
我已经成功使用Angular 2了一段时间,现在相同的代码(afaik)将无法编译.它将在browser.dmles/angular2/platform中找到"在browser.d.ts文件中找不到名称:Promise""
tsconfig.json
{
"compilerOptions": {
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"module": "commonjs",
"noEmitOnError": true,
"noImplicitAny": false,
"outDir": "../wwwroot/appScripts/",
"removeComments": false,
"sourceMap": true,
"target": "es5"
},
"exclude": [
"node_modules"
]
}
Run Code Online (Sandbox Code Playgroud)
的package.json
{
"version": "1.0.0",
"name": "asp.net",
"private": true,
"dependencies": {
"angular2": "2.0.0-beta.11",
"systemjs": "0.19.24",
"es6-promise": "^3.1.2",
"es6-shim": "^0.35.0",
"reflect-metadata": "0.1.2",
"rxjs": "5.0.0-beta.2",
"zone.js": "0.6.4"
},
"devDependencies": {
"gulp": "^3.9.1"
}
}
Run Code Online (Sandbox Code Playgroud)
gulpfile.js
/*
This file in the main entry point for defining Gulp tasks and using Gulp plugins.
Click here to learn more. http://go.microsoft.com/fwlink/?LinkId=518007
*/
/// <binding AfterBuild='moveToLibs' />
var gulp = require('gulp');
gulp.task('default', function () {
// place code for your default task here
});
gulp.task('moveToLibs', function () {
gulp.src([
'node_modules/angular2/bundles/js',
'node_modules/angular2/bundles/angular2.*.js*',
'node_modules/angular2/bundles/angular2-polyfills.js',
'node_modules/angular2/bundles/http.*.js*',
'node_modules/angular2/bundles/router.*.js*',
'node_modules/es6-shim/es6-shim.min.js*',
'node_modules/angular2/es6/dev/src/testing/shims_for_IE.js',
'node_modules/systemjs/dist/*.*',
'node_modules/jquery/dist/jquery.*js',
'node_modules/bootstrap/dist/js/bootstrap*.js',
'node_modules/rxjs/bundles/Rx.js'
]).pipe(gulp.dest('./wwwroot/libs/'));
});
Run Code Online (Sandbox Code Playgroud)
我甚至尝试在node_module/angular2/platform/browser.d.ts文件中使用引用路径,并且在非模块文件中使用引用路径引发了错误.
唯一有点工作(我没有完全实现它,因为它是疯了):将es6-promise.d.ts文件中的代码复制并粘贴到所有要求它的文件中.
编辑 嗅嗅 嗅嗅有东西在这里有难闻的气味:我决定重命名文件夹node_module到_bak_node_module_folder并重新安装所有的软件包:
Severity Code Description Project File Line Suppression State
Error MSB4018 The "FindConfigFiles" task failed unexpectedly.
System.IO.PathTooLongException: The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters.
at System.IO.Path.NormalizePath(String path, Boolean fullCheck, Int32 maxPathLength, Boolean expandShortPaths)
at System.IO.Path.GetDirectoryName(String path)
at System.IO.FileSystemEnumerableIterator`1..ctor(String path, String originalUserPath, String searchPattern, SearchOption searchOption, SearchResultHandler`1 resultHandler, Boolean checkHost)
at System.IO.Directory.EnumerateFiles(String path)
at TypeScript.Tasks.FileHelpers.RecursiveGatherFiles(String directoryPath, String projectPath, Func`2 filter)
at TypeScript.Tasks.FileHelpers.RecursiveGatherFiles(String directoryPath, String projectPath, Func`2 filter)
at TypeScript.Tasks.FileHelpers.RecursiveGatherFiles(String directoryPath, String projectPath, Func`2 filter)
at TypeScript.Tasks.FileHelpers.RecursiveGatherFiles(String directoryPath, String projectPath, Func`2 filter)
at TypeScript.Tasks.FileHelpers.RecursiveGatherFiles(String directoryPath, String projectPath, Func`2 filter)
at TypeScript.Tasks.FileHelpers.RecursiveGatherFiles(String directoryPath, String projectPath, Func`2 filter)
at TypeScript.Tasks.FileHelpers.RecursiveGatherFiles(String directoryPath, String projectPath, Func`2 filter)
at TypeScript.Tasks.FileHelpers.RecursiveGatherFiles(String directoryPath, String projectPath, Func`2 filter)
at TypeScript.Tasks.FileHelpers.RecursiveGatherFiles(String directoryPath, String projectPath, Func`2 filter)
at TypeScript.Tasks.FileHelpers.RecursiveGatherFiles(String directoryPath, String projectPath, Func`2 filter)
at TypeScript.Tasks.FileHelpers.RecursiveGatherFiles(String directoryPath, String projectPath, Func`2 filter)
at TypeScript.Tasks.FileHelpers.RecursiveGatherFiles(String directoryPath, String projectPath, Func`2 filter)
at TypeScript.Tasks.FileHelpers.RecursiveGatherFiles(String directoryPath, String projectPath, Func`2 filter)
at TypeScript.Tasks.FileHelpers.RecursiveGatherFiles(String directoryPath, String projectPath, Func`2 filter)
at TypeScript.Tasks.FileHelpers.RecursiveGatherFiles(String directoryPath, String projectPath, Func`2 filter)
at TypeScript.Tasks.FileHelpers.RecursiveGatherFiles(String directoryPath, String projectPath, Func`2 filter)
at TypeScript.Tasks.FileHelpers.RecursiveGatherFiles(String directoryPath, String projectPath, Func`2 filter)
at TypeScript.Tasks.FileHelpers.RecursiveGatherFiles(String directoryPath, String projectPath, Func`2 filter)
at TypeScript.Tasks.FileHelpers.RecursiveGatherConfigFiles(String directoryPath, String projectPath)
at TypeScript.Tasks.FindConfigFiles.FindConfigFilesOnDisk()
at TypeScript.Tasks.FindConfigFiles.Execute()
at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext() Angular2 C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\TypeScript\Microsoft.TypeScript.targets 153
Run Code Online (Sandbox Code Playgroud)
我真的很讨厌Windows的这个字符限制.如果这是问题所在,我想我会从我城市最高的桥上跳下来.
编辑x2 因此,我决定按照建议更新Visual Studio的NPM,但它没有成功.所以我决定抓住Nodejs并从cmd运行它.不幸的是问题仍然存在:
这是输出:
[0] node_modules/angular2/typings/browser.d.ts(6,14): error TS2300: Duplicate identifier 'PromiseConstructor'.
[0] node_modules/angular2/typings/es6-collections/es6-collections.d.ts(22,5): error TS2300: Duplicate identifier 'done'.
[0] node_modules/angular2/typings/es6-collections/es6-collections.d.ts(23,5): error TS2300: Duplicate identifier 'value'.
[0] node_modules/angular2/typings/es6-collections/es6-collections.d.ts(46,5): error TS2300: Duplicate identifier 'size'.
[0] node_modules/angular2/typings/es6-collections/es6-collections.d.ts(52,5): error TS2300: Duplicate identifier 'prototype'.
[0] node_modules/angular2/typings/es6-collections/es6-collections.d.ts(66,5): error TS2300: Duplicate identifier 'size'.
[0] node_modules/angular2/typings/es6-collections/es6-collections.d.ts(72,5): error TS2300: Duplicate identifier 'prototype'.
[0] node_modules/angular2/typings/es6-collections/es6-collections.d.ts(88,5): error TS2300: Duplicate identifier 'prototype'.
[0] node_modules/angular2/typings/es6-collections/es6-collections.d.ts(103,5): error TS2300: Duplicate identifier 'prototype'.
[0] node_modules/angular2/typings/es6-promise/es6-promise.d.ts(11,15): error TS2300: Duplicate identifier 'Promise'.
[0] node_modules/angular2/typings/es6-promise/es6-promise.d.ts(42,16): error TS2300: Duplicate identifier 'Promise'.
[0] typings/browser/ambient/es6-shim/index.d.ts(11,5): error TS2300: Duplicate identifier 'done'.
[0] typings/browser/ambient/es6-shim/index.d.ts(12,5): error TS2300: Duplicate identifier 'value'.
[0] typings/browser/ambient/es6-shim/index.d.ts(477,11): error TS2300: Duplicate identifier 'Promise'.
[0] typings/browser/ambient/es6-shim/index.d.ts(496,11): error TS2300: Duplicate identifier 'PromiseConstructor'.
[0] typings/browser/ambient/es6-shim/index.d.ts(554,13): error TS2300: Duplicate identifier 'Promise'.
[0] typings/browser/ambient/es6-shim/index.d.ts(563,5): error TS2300: Duplicate identifier 'size'.
[0] typings/browser/ambient/es6-shim/index.d.ts(572,5): error TS2300: Duplicate identifier 'prototype'.
[0] typings/browser/ambient/es6-shim/index.d.ts(583,5): error TS2300: Duplicate identifier 'size'.
[0] typings/browser/ambient/es6-shim/index.d.ts(592,5): error TS2300: Duplicate identifier 'prototype'.
[0] typings/browser/ambient/es6-shim/index.d.ts(607,5): error TS2300: Duplicate identifier 'prototype'.
[0] typings/browser/ambient/es6-shim/index.d.ts(621,5): error TS2300: Duplicate identifier 'prototype'.
[0] 2:47:31 PM - Compilation complete. Watching for file changes.
Run Code Online (Sandbox Code Playgroud)
小智 2
我在 Visual Studio 中很长时间遇到同样的问题。我注意到,如果您在尝试构建之前不等待所有 npm 依赖项恢复,那么您的项目就会陷入困境。
我的建议是,从 mithunvp.com 上的演示项目返回 package.json 文件中的原始依赖项版本。等待依赖关系恢复,然后重建 VS 项目。
对于字符限制问题,您必须在 Visual Studio 中更新 npm。
请参阅:在 Windows 上升级 npm
| 归档时间: |
|
| 查看次数: |
19579 次 |
| 最近记录: |