简体   繁体   English

找不到模块“ @ angular / core”。 找不到模块“ rxjs”

[英]Cannot find module '@angular/core'. Cannot find module 'rxjs'

Environment: 环境:

OS: Linux Mint 18 Cinnamon 64-bit 操作系统:Linux Mint 18 Cinnamon 64-bit
NPM: 5.6.0 NPM:5.6.0
Node: v10.0.0 节点:v10.0.0
Ionic: 3.20.0 离子性:3.20.0

How I receive this error 我如何收到此错误

I was following this tutorial to apply firebase to an ionic project using angularfire2. 我按照本教程进行操作,以便使用angularfire2将firebase应用于离子项目。 I follow the tutorial exactly until I receive an error while running 我完全按照本教程操作,直到在运行时收到错误消息为止

$ ionic serve

The full error is like this: 完整的错误是这样的:

typescript: home/brian/node_modules/angularfire2/angularfire2.d.ts, line: 1 
Cannot find module '@angular/core'. 

L1:  import { InjectionToken, NgZone } from '@angular/core';
L2:  import { Observable, Subscription } from 'rxjs';

typescript: home/brian/node_modules/angularfire2/angularfire2.d.ts, line: 2 
Cannot find module 'rxjs'. 

L1:  import { InjectionToken, NgZone } from '@angular/core';
L2:  import { Observable, Subscription } from 'rxjs';
L3:  import { FirebaseOptions, FirebaseAppConfig } from '@firebase/app-types';

typescript: home/brian/node_modules/angularfire2/auth/auth.d.ts, line: 3 
Cannot find module '@angular/core'. 

L2:  import { FirebaseOptions, FirebaseAppConfig } from '@firebase/app-types';
L3:  import { NgZone } from '@angular/core';
L4:  import { Observable } from 'rxjs';

typescript: home/brian/node_modules/angularfire2/auth/auth.d.ts, line: 4 
Cannot find module 'rxjs'. 

L3:  import { NgZone } from '@angular/core';
L4:  import { Observable } from 'rxjs';
L5:  export declare class AngularFireAuth {

typescript: home/brian/node_modules/angularfire2/firebase.app.module.d.ts, line: 1 
Cannot find module '@angular/core'. 

L1:  import { InjectionToken } from '@angular/core';
L2:  import { FirebaseApp as _FirebaseApp, FirebaseOptions, FirebaseAppConfig } from '@firebase/app-types';

Traceback 追溯

Tracing back, when I was installing angularfire2 through command line, I run this command ( following the documentation ) 回溯一下,当我通过命令行安装angularfire2时,我运行了此命令( 遵循文档

npm install firebase angularfire2 --save

And it returns this: 它返回此:

npm WARN registry Unexpected warning for https://registry.npmjs.org/: Miscellaneous Warning EAI_AGAIN: request to https://registry.npmjs.org/firebase failed, reason: getaddrinfo EAI_AGAIN registry.npmjs.org registry.npmjs.org:443
npm WARN registry Using stale package data from https://registry.npmjs.org/ due to a request error during revalidation.
npm WARN angularfire2@5.0.0-rc.7 requires a peer of @angular/common@^5.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN angularfire2@5.0.0-rc.7 requires a peer of @angular/core@^5.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN angularfire2@5.0.0-rc.7 requires a peer of @angular/platform-browser@^5.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN angularfire2@5.0.0-rc.7 requires a peer of @angular/platform-browser-dynamic@^5.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN angularfire2@5.0.0-rc.7 requires a peer of @firebase/app@^0.1.6 but none is installed. You must install peer dependencies yourself.
npm WARN angularfire2@5.0.0-rc.7 requires a peer of rxjs@^5.5.4 but none is installed. You must install peer dependencies yourself.
npm WARN angularfire2@5.0.0-rc.7 requires a peer of zone.js@^0.8.0 but none is installed. You must install peer dependencies yourself.
npm WARN bin@1.0.0 No description
npm WARN bin@1.0.0 No repository field.

+ angularfire2@5.0.0-rc.7
+ firebase@5.0.2
updated 2 packages in 80.502s

Then I try to run the same command again, now it returns almost the same as above but without the npm WARN registry . 然后,我尝试再次运行相同的命令,现在它返回的结果几乎与上面相同,但是没有npm WARN注册表

npm WARN angularfire2@5.0.0-rc.8.0 requires a peer of @angular/common@^6.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN angularfire2@5.0.0-rc.8.0 requires a peer of @angular/core@^6.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN angularfire2@5.0.0-rc.8.0 requires a peer of @angular/platform-browser@^6.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN angularfire2@5.0.0-rc.8.0 requires a peer of @angular/platform-browser-dynamic@^6.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN angularfire2@5.0.0-rc.8.0 requires a peer of rxjs@^6.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN angularfire2@5.0.0-rc.8.0 requires a peer of zone.js@^0.8.0 but none is installed. You must install peer dependencies yourself.
npm WARN bin@1.0.0 No description
npm WARN bin@1.0.0 No repository field.

The file package.json is located in /home/brian and it contains the lines below. package.json文件位于/ home / brian中,并且包含以下几行。

{
  "name": "bin",
  "version": "1.0.0",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "description": "",
  "dependencies": {
    "angular": "^1.7.0",
    "angularfire2": "^5.0.0-rc.8.0",
    "cordova": "^8.0.0",
    "firebase": "^5.0.2",
    "ionic": "^3.20.0",
    "npm": "^6.0.1"
  }
}

There is this text in browser after i run $ ionic serve 我运行$ ionic serve后浏览器中有此文本

Ionic Framework: 3.9.2
Ionic App Scripts: 3.1.9
Angular Core: 5.2.10
Angular Compiler CLI: 5.2.10
Node: 10.0.0
OS Platform: Linux 4.4
Navigator Platform: Linux x86_64
User Agent: Mozilla/5.0 (X11; Linux x86_64; rv:57.0) Gecko/20100101 Firefox/57.0

I think I installed angularfire on the same location as npm and node, because I run all these installation command in my default location when opening command line. 我认为我在与npm和node相同的位置安装了angularfire,因为打开命令行时,我在默认位置运行了所有这些安装命令。 It should be in /home/brian. 它应该在/ home / brian中。 I also have this folder /home/brian/node_modules. 我也有这个文件夹/ home / brian / node_modules。

My Google research to solve this 我的Google研究来解决这个问题

This similar thread says that we need to rename @angular to @angular2, but I found it returns same error. 这个类似的线程说我们需要将@angular重命名为@ angular2,但是我发现它返回了相同的错误。

Does anyone ever experience the same issue? 有人遇到过同样的问题吗? Any help would be appreciated. 任何帮助,将不胜感激。

Based on you version info of ionic v 3.9.2 , you need to install angular V4.4.6 , refer ionic dependencies . 根据ionic v 3.9.2的版本信息,您需要安装angular V4.4.6 ,请参考ionic 依赖项 BTW, when you don't declare the exact version you want to install, npm will install the latest version by default . 顺便说一句,当您未声明要安装的确切版本时, npm默认安装最新版本

You can use below command: 您可以使用以下命令:

// all angular packages listed in above dependencies 
npm install @angular/[package-name]@4.4.6

And based on version of angular packages, you should install AngularFire2 **v5.0.0-rc.3 ** and rxjs of v5.0.1+(not v6.x) . 根据角度软件包的版本,您应该安装AngularFire2 ** v5.0.0-rc.3 **和rxjs +(而非v6.x)的rxjs

npm install firebase@4.5.0 angularfire2@5.0.0-rc.3 --save
npm install rxjs@5.0.1 --save

Thanks @Pengyy, your suggestion is really close to fix it, just need to add one more step. 感谢@Pengyy,您的建议真的很接近可以解决,只需要再增加一个步骤即可。

This error is caused by the non compatible versions I used accross ionic - @angular/core - firebase - angularfire2 - and rxjs. 此错误是由于我跨离子使用的不兼容版本引起的-@ angular / core-firebase-angularfire2-和rxjs。

The way I solve it is is following @Pengyy's answer: 我解决的方法是遵循@Pengyy的答案:

In my home folder /home/brian run 在我的主文件夹/home/brian run中

  1. npm install @angular/[package-name]@4.4.6
  2. npm install firebase@4.5.0 angularfire2@5.0.0-rc.3 --save
  3. npm install rxjs@5.0.1 --save

Then need to do one more step: in my ionic project folder where I run ionic serve, (eg project name is myApp the folder is /home/brian/myApp ) run this command. 然后需要执行另一步:在运行ionic serve的ionic项目文件夹中(例如,项目名称为myApp,文件夹为/home/brian/myApp )运行此命令。

  1. npm install firebase@4.5.0

This last step is necessary, otherwise I still got an error 最后一步是必要的,否则我仍然会出错

Runtime Error 
Cannot find module "firebase/auth"

This problem is solved! 这个问题解决了!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM