Angular2找不到模块'angular2 /核心“,但应用程序的工作 [英] Angular2 Cannot find module 'angular2/core' but application works

查看:3565
本文介绍了Angular2找不到模块'angular2 /核心“,但应用程序的工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于我已经应用在编写与Angular2 app.component.ts 和一些进口的:

 进口{}组件从angular2 /核心;进口{} FiltersService从./services/filters-service
进口{} SearchPipe从./pipes/header-pipe
从./pipes/pagination-pipe进口{PaginationPipe};
进口{}标题从./components/header/header.component
进口{}分页从./components/pagination/pagination.component
进口{}的ConfigService从./services/config-service
进口{} ResourceService从./services/resource-service
从./services/http-service进口{} HttpService的;进口'rxjs /添加/运营/图;
进口{} GlobalSearch从./components/global-search/global-search.component
进口{} GlobalSearchPipe从./pipes/global-search-pipe
进口{} CsvExport从./components/dropdown/csv-export.component
从angular2 / HTTP进口{HTTP_PROVIDERS};

当我按 NPM启动启动应用程序,该应用程序正在启动并正常工作,但在控制台中我得到:

 应用程序/ app.component.ts(1,25):错误TS2307:找不到模块'angular2 /核心。
应用程序/ app.component.ts(18,30):错误TS2307:找不到模块'angular2 / HTTP。


解决方案

在事实上,这里有两部分组成:


  • 编辑部分依赖于分型(d.ts文件)。如果不能使用的对象/类的定义中找到这些文件,你将有编译错误。这不会停止编译过程。看到这个问题的更多细节:没有不d.ts文件编译错误


  • 运行部分依赖于JavaScript文件。如果相应的文件包含或可通过模块管理器,你将能够使用它们。


在你的情况,我认为可以达到 core.d.ts 文件编译过程中。当您用值来配置你的编译器节点 moduleResolution 属性,则(TSC)寻找它内 node_modules 文件夹中。

Given I have app written in Angular2 with app.component.ts and some imports in it:

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:

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). 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.

  • The runtime part that relies on JavaScript files. 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. When you configure your compiler with the value node for the moduleResolution property , it will (tsc) look for it within the node_modules folder.

这篇关于Angular2找不到模块'angular2 /核心“,但应用程序的工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆