각도 및 활자 문자:이름을 찾을 수 없음 - 오류: 이름을 찾을 수 없습니다.
TypeScript(버전 1.6)에서 Angular(버전 2)를 사용하고 있는데 코드를 컴파일하면 다음 오류가 발생합니다.
Error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/core/change_detection/parser/locals.d.ts(4,42): Error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/core/facade/collection.d.ts(1,25): Error TS2304: Cannot find name 'MapConstructor'.
node_modules/angular2/src/core/facade/collection.d.ts(2,25): Error TS2304: Cannot find name 'SetConstructor'.
node_modules/angular2/src/core/facade/collection.d.ts(4,27): Error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/core/facade/collection.d.ts(4,39): Error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/core/facade/collection.d.ts(7,9): Error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/core/facade/collection.d.ts(8,30): Error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/core/facade/collection.d.ts(11,43): Error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/core/facade/collection.d.ts(12,27): Error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/core/facade/collection.d.ts(14,23): Error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/core/facade/collection.d.ts(15,25): Error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/core/facade/collection.d.ts(94,41): Error TS2304: Cannot find name 'Set'.
node_modules/angular2/src/core/facade/collection.d.ts(95,22): Error TS2304: Cannot find name 'Set'.
node_modules/angular2/src/core/facade/collection.d.ts(96,25): Error TS2304: Cannot find name 'Set'.
node_modules/angular2/src/core/facade/lang.d.ts(1,22): Error TS2304: Cannot find name 'BrowserNodeGlobal'.
node_modules/angular2/src/core/facade/lang.d.ts(33,59): Error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/core/facade/promise.d.ts(1,10): Error TS2304: Cannot find name 'Promise'.
node_modules/angular2/src/core/facade/promise.d.ts(3,14): Error TS2304: Cannot find name 'Promise'.
node_modules/angular2/src/core/facade/promise.d.ts(8,32): Error TS2304: Cannot find name 'Promise'.
node_modules/angular2/src/core/facade/promise.d.ts(9,38): Error TS2304: Cannot find name 'Promise'.
node_modules/angular2/src/core/facade/promise.d.ts(10,35): Error TS2304: Cannot find name 'Promise'.
node_modules/angular2/src/core/facade/promise.d.ts(10,93): Error TS2304: Cannot find name 'Promise'.
node_modules/angular2/src/core/facade/promise.d.ts(11,34): Error TS2304: Cannot find name 'Promise'.
node_modules/angular2/src/core/facade/promise.d.ts(12,32): Error TS2304: Cannot find name 'Promise'.
node_modules/angular2/src/core/facade/promise.d.ts(12,149): Error TS2304: Cannot find name 'Promise'.
node_modules/angular2/src/core/facade/promise.d.ts(13,43): Error TS2304: Cannot find name 'Promise'.
node_modules/angular2/src/core/linker/element_injector.d.ts(72,32): Error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/core/linker/element_injector.d.ts(74,17): Error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/core/linker/element_injector.d.ts(78,184): Error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/core/linker/element_injector.d.ts(83,182): Error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/core/linker/element_injector.d.ts(107,37): Error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/core/linker/proto_view_factory.d.ts(27,146): Error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/core/linker/view.d.ts(52,144): Error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/core/linker/view.d.ts(76,79): Error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/core/linker/view.d.ts(77,73): Error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/core/linker/view.d.ts(94,31): Error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/core/linker/view.d.ts(97,18): Error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/core/linker/view.d.ts(100,24): Error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/core/linker/view.d.ts(103,142): Error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/core/linker/view.d.ts(104,160): Error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/core/render/api.d.ts(281,74): Error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/core/zone/ng_zone.d.ts(1,37): Error TS2304: Cannot find name 'Zone'.
코드는 다음과 같습니다.
import 'reflect-metadata';
import {bootstrap, Component, CORE_DIRECTIVES, FORM_DIRECTIVES} from 'angular2/core';
@Component({
selector: 'my-app',
template: '<input type="text" [(ng-model)]="title" /><h1>{{title}}</h1>',
directives: [ CORE_DIRECTIVES ]
})
class AppComponent {
title :string;
constructor() {
this.title = 'hello angular 2';
}
}
bootstrap(AppComponent);
2.0.0-beta.6(2016-02-11)에 관한 changelog에 기재되어 있는 회피책이 있습니다(변경을 해제하는 아래에 기재되어 있습니다).
--target=es5를 사용하는 경우 응용 프로그램의 어딘가에 행을 추가해야 합니다(예를 들어 부트스트랩을 호출하는 .ts 파일의 맨 위).
///<reference path="node_modules/angular2/typings/browser.d.ts"/>
(파일이 node_modules 와 같은 디렉토리에 없는 경우는, 그 패스의 선두에 1개 또는 복수의 ../ 를 추가할 필요가 있습니다).
올바른 참조 경로가 있는지 확인하십시오. 이 작업을 수행하려면 시작 부분에 ../를 추가해야 했습니다.
약속과 같은 ES6 기능은 ES5를 대상으로 할 때 정의되지 않습니다.다른 라이브러리가 있지만, core-js는 Angular 팀이 사용하는 Javascript 라이브러리입니다.ES6용 폴리필이 포함되어 있습니다.
앵글2는 이 질문 이후로 많이 바뀌었어요.유형 선언은 유형 스크립트 2.0에서 훨씬 쉽게 사용할 수 있습니다.
npm install -g typescript
Angular 2의 ES6 기능에는 타이핑이 필요하지 않습니다.typescript 2.0 이후를 사용하여 npm과 함께 @types/core-js를 설치합니다.
npm install --save-dev @types/core-js
그런 다음 TypeRoots 및 Types 속성을 tsconfig.json에 추가합니다.
{
"compilerOptions": {
"target": "es5",
"module": "es6",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": false,
"typeRoots": [
"../node_modules/@types"
],
"types" : [
"core-js"
]
},
"exclude": [
"node_modules"
]
}
이는 다른 답변에서 설명한 것처럼 오타를 사용하는 것보다 훨씬 쉽습니다.상세한 것에 대하여는, Microsoft 의 블로그 투고를 참조해 주세요.타이프스크립트: 선언 파일의 미래
이미 알려진 문제: https://github.com/angular/angular/issues/4902
이유: " " " " :.d.ts에 암묵적으로 대상에 TypeScript를 대상으로 할 합니다.es5런타임에 실제로 물건이 존재하더라도(예: 크롬).자세한 것은 이쪽
Angular2에 대한 합니다.angular.io명확하게 하기 위해 코드를 어디에 배치해야 하는지에 대한 mvdluit의 답변은 다음과 같습니다.
의 ★★★★★★★★★★★★★★★★★.main.ts요.
/// <reference path="../node_modules/angular2/typings/browser.d.ts" />
import {bootstrap} from 'angular2/platform/browser'
import {AppComponent} from './app.component'
// Add all operators to Observable
import 'rxjs/Rx'
bootstrap(AppComponent);
남겨두는 것에 해 주세요.///이치노
참조: https://github.com/ericmdantas/angular2-typescript-todo/blob/master/index.ts#L1
다음 명령으로 이 문제를 해결할 수 있었습니다.
typings install es6-promise es6-collections --ambient
「 」가해 주세요.typings동작하도록 되어 있지 다음 을 실행하여 합니다.
npm install -g typings
갱신하다
안 요.--ambient it it it it it --global 상기 의 정의를 할 가 있는 는, .
typings install dt~es6-promise dt~es6-collections --global --save
이것을 지적해 주신 @bgerth님 감사합니다.
Typescript > = 2인 경우 tsconfig.json의 "lib" 옵션이 작업을 수행합니다.타이핑은 필요 없습니다.https://www.typescriptlang.org/docs/handbook/compiler-options.html
{
"compilerOptions": {
"target": "es5",
"lib": ["es2016", "dom"] //or es6 instead of es2016(es7)
}
}
★★★의 Angular 2.0.0-rc.0, 「」의node_modules/angular2/typings/browser.d.ts작동하지 않습니다.먼저 다음 내용을 포함한 typings.json 파일을 솔루션에 추가합니다.
{
"ambientDependencies": {
"es6-shim": "github:DefinitelyTyped/DefinitelyTyped/es6-shim/es6-shim.d.ts#7de6c3dd94feaeb21f20054b9f30d5dabc5efabd"
}
}
" " " 를 합니다.package.json를 postinstall:
"scripts": {
"postinstall": "typings install"
},
" " " 를 실행합니다.npm install
, 이 에서는, 「무시」를 무시해 .typings는 ""」에 격납되어 있습니다.tsconfig.json★★★★
"exclude": [
"node_modules",
"typings/main",
"typings/main.d.ts"
]
갱신하다
AngularJS은 "AngularJS 2.0"을 사용하고 .core-jses6-shim자세한 내용은 빠른 시작 타이핑.json 파일을 참조하십시오.
.ts 파일의 선두에 코드를 추가할 수 있습니다.
/// <reference path="../typings/index.d.ts" />
Angular 2 rc1 서 angular angular 。이 v1 구 0로.browser.d.ts이 일일 files files files files가 되었다.index.d.ts.
" " " 후typings install스타트업 파일(부트스트랩 위치)을 찾아 다음을 추가합니다.
/// <reference path="../typings/index.d.ts" /> (이탈리아)가 없으면../스타트업 파일이 타이핑 폴더와 같은 폴더에 있는 경우)
" " " index.d.ts 목록으로 이동합니다.tsconfig.json어떤 이유에서인지 작동하지 않았다.
,,es6-shim패키지는 필요 없습니다.
by제결inginging를 으로써 이 할 수 .typings★★★★★★ 。
npm install -g typings
typings install
(ng 2.0.0-rc.1 사용)
도 같은 '부터'를 요.lib입니다.tsconfig.json그의 답변에서 basarat가 말한 것처럼,.d.ts TypeScript에 됩니다.target만, 이 은, 「다음에」, 「다음에」, 「다음에」, 「다음에」, 「다음에」, 「다음에,lib★★★★★★ 。
대상 JS 버전을 변경하지 않고 포함할 추가 정의 파일을 지정할 수 있습니다.를 들어, 이것은 사용하고 있는 예예, of of for of 、 of 、 것 for for for for for 。compilerOptionsTypescript및 Typescript@2에 되었습니다.1의es2015하다
"compilerOptions": {
"experimentalDecorators": true,
"lib": ["es5", "dom", "es6", "dom.iterable", "scripthost"],
"module": "commonjs",
"moduleResolution": "node",
"noLib": false,
"target": "es5",
"types": ["node"]
}
사용 가능한 옵션의 전체 목록은 공식 문서를 참조하십시오.
가 덧붙인 은 '아, 아, 아, 아, 아, 아, 아, 아, 아, 아, 아, 아, 아, 아, 아, 아, 아, 아, 아, 아, 아."types": ["node"]를 인스톨 했습니다.npm install @types/noderequire('some-module')내 코드로.
typings install dt~es6-shim --save --global
올바른 경로를 index.d.ts에 추가합니다.
///<reference path="../typings/index.d.ts"/>
@angular-2.0.0-rc3에서 시행.
ifnpm install -g typings typings install그래도 이 명령어를 실행하기 전에 node_module 및 타이핑 폴더를 삭제해도 도움이 되지 않습니다.
이것은 모두가 어떻게 다른 것을 하려고 하는지 생각하는 것이다.이 시스템은 아직 최종 버전과는 거리가 멀다고 생각합니다.
저의 경우 rc.0에서rc.5로 업데이트했습니다.
수정은 tsconfig.json을 변경하는 것이었습니다.
{
"compilerOptions": {
"target": "es6", <-- It was es5
"module": "system",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": false,
"outDir": "../wwwroot/app"
},
"compileOnSave": true,
"exclude": [
"../node_modules",
"../typings/main"
]
}
응용 프로그램의 메인 폴더에 typing.d.ts를 추가하고, 거기에서 매번 사용할 변수를 선언합니다.
declare var System: any;
declare var require: any;
이것을 typing.d.ts 로 선언한 후, require 에러는 애플리케이션에 표시되지 않습니다.
Angular는 처음이지만, 저는 Input을 Import하는 것만으로 해결했습니다.이건 믿을 수 없어 다른 게시판에서 찾았어같은 문제가 있는 경우에는 간단한 수정이지만, 문제가 더 복잡하다면 위의 내용을 읽겠습니다.
무케시:
하위 구성 요소 위에 이와 같은 입력을 가져와야 합니다.
import { Directive, Component, OnInit, Input } from '@angular/core';
Angular 2의 웹사이트에서 매우 도움이 되는 문서를 찾았습니다.그 결과, 올바르게 동작할 수 있게 되었습니다만, 타이핑의 인스톨에 관한 다른 답변은 여러가지 에러로 실패했습니다(그러나, 올바른 방향으로 인도하는 데 도움이 되었습니다).
es6-promise와 es6-collections를 포함하는 대신 core-js를 포함하고 있습니다.그것은 나에게 효과가 있었습니다.Angular2의 핵심 ts 정의와 충돌하지 않습니다.또, 이 문서에서는, NPM 의 인스톨시에 이 모든 것이 자동적으로 행해지도록 설정하는 방법, 및 typings.json 파일을 변경하는 방법에 대해서도 설명하고 있습니다.
개발 브랜치를 현재 브랜치로 병합한 후 이 오류가 발생했습니다.나는 그 문제를 해결하기 위해 잠시 시간을 보냈다.아래 그림과 같이 코드에는 전혀 문제가 없습니다.
따라서 VSCode를 재시작하는 것만이 유일한 해결 방법입니다.
Angular 2 RC1의 이름은node_modules/angular2로의 디렉토리.node_modules/angular.
gulp 파일을 사용하여 파일을 출력 디렉토리에 복사하는 경우node_modules/angular컴파일러가 잡아서 혼란스럽게 만들 수도 있어요
그래서 (조심해서) 가지고 있는 것을 삭제해 주세요.node_modules베타 버전용이며 오래된 타이핑도 삭제하고 다시 실행합니다.typings install.
JS 파일에서 다음 문을 가져오십시오.
import 'rxjs/add/operator/map';
받아들여진 답변은 실행 가능한 해결책을 제공하지 않습니다.그리고 다른 답변의 대부분은 실행 불가능한 "트리플 슬래시" 회피책을 제안합니다.이러한 회피책은,browser.d.ts는 Angular2 최신 RC에 의해 삭제되어 더 이상 사용할 수 없습니다.
권합니다.typings이 모듈에서는 몇 가지 솔루션을 제안하지만 수동으로 또는 글로벌하게 수행할 필요가 없습니다. VS2015 인터페이스 내에서만 효과적인 방법으로 프로젝트를 수행할 수 있습니다.필요한 것은 다음과 같습니다.
typingsfile. file.json.json 。- 덧붙이다
scriptpackage.json" " " / " " "typings【NPM】【NPM】【NPM】【NPM】【NPM】【NPM】【NPM】. - 덧붙이다
typings.json에 있는 되어 있습니다.core-js)es6-shimatm을
바로 그겁니다.
기타 SO 스레드도 확인하실 수 있습니다.또한 자세한 내용은 제 블로그에 대한 자세한 내용은 이쪽을 참조하십시오.
잘 했어, @VahidN, 내가 필요하단 걸 알았어
"exclude": [
"node_modules",
"typings/main",
"typings/main.d.ts"
]
의 마마 my에서는tsconfig에러를 막기 위해서도es6-shim 자체
Import가 누락되어 있을 수 있습니다.
예:
src/app/products/products.component.ts:15:15 - 오류 TS2304: 이름을 찾을 수 없습니다.IProduct'입니다.
파일 상단에 Import를 추가합니다.
import { IProduct } from './product';
...
export class ProductListComponent {
pageTitle: string = 'product list!';
imageWidth: number = 50;
imageMargin: number = 2;
showImage: boolean = false;
listFilter: string = 'cart';
products: IProduct[] = ... //cannot find name error
이제 수동으로 Import해야 합니다.
import 'rxjs/add/operator/retry';
import 'rxjs/add/operator/timeout';
import 'rxjs/add/operator/delay';
import 'rxjs/add/operator/map';
this.http.post(url, JSON.stringify(json), {headers: headers, timeout: 1000})
.retry(2)
.timeout(10000, new Error('Time out.'))
.delay(10)
.map((res) => res.json())
.subscribe(
(data) => resolve(data.json()),
(err) => reject(err)
);
tsconfig.json, 변경
"target": "es5"
로.
"target": "es6"
언급URL : https://stackoverflow.com/questions/33332394/angular-and-typescript-cant-find-names-error-cannot-find-name
'programing' 카테고리의 다른 글
| MUI에서 커스텀 애니메이션 효과 @keyframes를 적용하는 방법 (0) | 2023.03.11 |
|---|---|
| TypeScript에서 어레이 선언 (0) | 2023.03.11 |
| ASP에서의 Access-Control-Allow-Origin 설정.Net MVC - 가장 간단한 방법 (0) | 2023.03.11 |
| 다이내믹 템플릿을 사용하여 Angular 2.0을 사용하여 다이내믹 컴포넌트를 컴파일하려면 어떻게 해야 합니까? (0) | 2023.03.11 |
| WordPress API의 데이터 설정 해제(wp-json) (0) | 2023.03.11 |
