[英]Angular2 Cannot find module 'angular2/core' but application works
Given I have app written in Angular2 with app.component.ts
and some imports in it:鉴于我有一个用app.component.ts
编写的应用程序,其中包含app.component.ts
和一些导入:
import {Component} from 'angular2/core';
import {FiltersService} from "./services/filters-service";
import {SearchPipe} from "./pipes/header-pipe";
import {PaginationPipe} from "./pipes/pagination-pipe";
import {Header} from "./components/header/header.component";
import {Pagination} from "./components/pagination/pagination.component";
import {ConfigService} from "./services/config-service";
import {ResourceService} from "./services/resource-service";
import {HttpService} from "./services/http-service";
import 'rxjs/add/operator/map';
import {GlobalSearch} from "./components/global-search/global-search.component";
import {GlobalSearchPipe} from "./pipes/global-search-pipe";
import {CsvExport} from "./components/dropdown/csv-export.component";
import {HTTP_PROVIDERS} from "angular2/http";
When I start app by npm start
, the app is starting and works properly, but in the console I am getting:当我通过npm start
启动应用npm start
,应用程序正在启动并正常工作,但在控制台中我得到:
app/app.component.ts(1,25): error TS2307: Cannot find module 'angular2/core'.
app/app.component.ts(18,30): error TS2307: Cannot find module 'angular2/http'.
In fact, there are two parts here:其实这里有两部分:
The compilation part that relies on typings (d.ts files).依赖类型(d.ts 文件)的编译部分。 If these files can't be found for the definition of objects / classes used, you will have compilation error.如果无法为所用对象/类的定义找到这些文件,则会出现编译错误。 This won't stop the compilation process.这不会停止编译过程。 See this question for more details: No compilation error without d.ts files .有关更多详细信息,请参阅此问题: No compiler error without d.ts files 。
The runtime part that relies on JavaScript files.依赖于 JavaScript 文件的运行时部分。 If corresponding files are included or available through the module manager, you will be able to use them.如果通过模块管理器包含或提供相应的文件,您将能够使用它们。
In your case, I think that you can reach the core.d.ts
file during compilation.在您的情况下,我认为您可以在编译期间访问core.d.ts
文件。 When you configure your compiler with the value node
for the moduleResolution
property , it will (tsc) look for it within the node_modules
folder.当您用值来配置你的编译器node
的moduleResolution
财产它将(TSC)的外观为它内部的, node_modules
文件夹。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.