问题描述
在Angular2 TS快速入门之后,我最终在项目中的许多文件夹中都有重复的文件.
Following the Angular2 TS Quickstart, I end up having duplicate files in many folders across my project.
对于浏览器:
typings/browser
node_modules/angular2/typings/browser
对于es6-shim:
For es6-shim:
node_modules/angular2/typings/es6-shim
typings/browser/ambient/es6-shim
typings/main/ambient/es6-shim
这会导致在构建过程中出现重复标识符错误.
It results in Duplicate Identifier errors during build.
我们如何防止/抑制TS引发重复的标识符错误?
How do we prevent / suppress TS from raising duplicate identifier errors?
我已将node_modules包含在我的排除列表中,但是,由于我在包含中使用了Angular2,因此由于moduleResolution节点",TSD会将它们包含回去.替换为另一个moduleResolution值(例如经典")会导致其他问题.
这是我的tsconfig.json:
This is my tsconfig.json:
{
"compilerOptions": {
"target": "es5",
"module": "system",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": false,
"outDir": "./dist"
},
"exclude": [
"bower_components",
"node_modules",
"typings/main",
"typings/main.d.ts"
]
}
更新1
这是我的appcomponent.ts:
Here's my appcomponent.ts:
///<reference path="../../node_modules/angular2/typings/browser.d.ts"/>
import {bootstrap} from 'angular2/platform/browser';
import {LocationComponent} from '../location/components/locationcomponent';
import {VideosComponent} from '../videos/components/videoscomponent';
bootstrap(LocationComponent, [])
.catch(err => console.error(err));
bootstrap(VideosComponent, [])
.catch(err => console.error(err));
更新2
这是我的Web项目文件所拥有的.
This is what I have for my web project file.
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" />
<PropertyGroup Label="Globals">
<ProjectGuid>3775534b-d08c-45f2-8d5a-4a4f6e91edb9</ProjectGuid>
<RootNamespace>MyProject</RootNamespace>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">..\..\artifacts\bin\$(MSBuildProjectName)\</OutputPath>
<SccProjectName>SAK</SccProjectName>
<SccProvider>SAK</SccProvider>
<SccAuxPath>SAK</SccAuxPath>
<SccLocalPath>SAK</SccLocalPath>
</PropertyGroup>
<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)' == 'Debug'">
<TypeScriptTarget>ES5</TypeScriptTarget>
<TypeScriptJSXEmit>None</TypeScriptJSXEmit>
<TypeScriptCompileOnSaveEnabled>True</TypeScriptCompileOnSaveEnabled>
<TypeScriptNoImplicitAny>False</TypeScriptNoImplicitAny>
<TypeScriptModuleKind>CommonJS</TypeScriptModuleKind>
<TypeScriptRemoveComments>False</TypeScriptRemoveComments>
<TypeScriptOutFile />
<TypeScriptModuleResolution>NodeJs</TypeScriptModuleResolution>
<TypeScriptOutDir />
<TypeScriptGeneratesDeclarations>False</TypeScriptGeneratesDeclarations>
<TypeScriptNoEmitOnError>True</TypeScriptNoEmitOnError>
<TypeScriptSourceMap>True</TypeScriptSourceMap>
<TypeScriptMapRoot />
<TypeScriptSourceRoot />
<TypeScriptExperimentalDecorators>True</TypeScriptExperimentalDecorators>
</PropertyGroup>
<Target Name="FixTsBuildConfiguration" BeforeTargets="CompileTypeScript" >
<PropertyGroup>
<TypeScriptBuildConfigurations>$(TypeScriptBuildConfigurations.Replace("--moduleResolution NodeJs", "--moduleResolution node"))</TypeScriptBuildConfigurations>
</PropertyGroup>
</Target>
<ItemGroup>
<DnxInvisibleContent Include="bower.json" />
<DnxInvisibleContent Include=".bowerrc" />
<DnxInvisibleContent Include="package.json" />
<DnxInvisibleFolder Include="wwwroot\bower_components\" />
<DnxInvisibleFolder Include="wwwroot\node_modules\" />
</ItemGroup>
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>
更新3
我发现在Visual Studio 2015中设置Angular2需要另一种方法.我按照在ASP.NET 5中启动Angular 2中的步骤进行操作.使用Visual Studio 2015使用TypeScript ,我再也没有遇到任何构建问题.
I found out that setting up Angular2 in Visual Studio 2015 requires another approach. I followed the steps in Starting Angular 2 in ASP.NET 5 with TypeScript using Visual Studio 2015 and I didn't get any build issues anymore.
推荐答案
我发现在Visual Studio 2015中设置Angular2需要另一种方法.我按照S tarting Angular中的步骤进行操作使用Visual Studio 2015的TypeScript在ASP.NET 5中使用2 ,而我再也没有遇到任何构建问题.
I found out that setting up Angular2 in Visual Studio 2015 requires another approach. I followed the steps in Starting Angular 2 in ASP.NET 5 with TypeScript using Visual Studio 2015 and I didn't get any build issues anymore.
这篇关于Angular2 Typescript文件的重复标识符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!