简体   繁体   English

离子未捕获错误:导入服务提供商时找不到模块“。”

[英]Ionic Uncaught Error: Cannot find module “.” when importing a service provider

I am trying to import a new service provider that I just created after pulling from the latest branch in my ionic app. 我正在尝试导入一个新的服务提供商,该服务提供商是从ionic应用程序的最新分支中提取后创建的。

When I try to import this line of code: 当我尝试导入以下代码行时:

import { AuthServiceProvider } from '../providers/auth-service'

in app.module.ts I always got an error saying that: app.module.ts中,我总是收到一条错误消息:

 Uncaught Error: Cannot find module "." at webpackMissingModule (index.js:3) at e.code (index.js:3) at Object.<anonymous> (index.js:9) at __webpack_require__ (bootstrap 62d6a5897825ac327001:54) at Object.690 (slide.transition.ts:67) at __webpack_require__ (bootstrap 62d6a5897825ac327001:54) at Object.495 (main.js:1885) at __webpack_require__ (bootstrap 62d6a5897825ac327001:54) at Object.487 (notification-api.ts:6) at __webpack_require__ (bootstrap 62d6a5897825ac327001:54) 

But take note that I am also importing another service from my provider that is working perfectly. 但是请注意,我也正在从提供商中导入另一个运行良好的服务。

Here is the code of my auth-service.ts below. 这是下面我的auth-service.ts的代码。

import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Events } from 'ionic-angular/umd';

/*
  Generated class for the AuthServiceProvider provider.

  See https://angular.io/guide/dependency-injection for more info on providers
  and Angular DI.
*/
@Injectable()
export class AuthServiceProvider {

  public isLoggedIn = false;

  constructor(
    public http: HttpClient,
    private events: Events
  ) {
    console.log('Hello AuthServiceProvider Provider');

    events.subscribe('user:logged-in', (user) => {
      this.isLoggedIn = true;
      console.log('Welcome', user);
    });
  }

}

I won't show my code in my app.module.ts because it is bombarded by import plugins and other providers. 我不会在我的app.module.ts中显示代码,因为它会被导入插件和其他提供程序轰炸。

Here is my ionic info 这是我的离子信息

cli packages: (/usr/lib/node_modules)

@ionic/cli-utils  : 1.19.2
ionic (Ionic CLI) : 3.20.0

global packages: 全局软件包:

cordova (Cordova CLI) : 8.0.0 

local packages: 本地套餐:

@ionic/app-scripts : 3.1.8
Cordova Platforms  : android 6.3.0 browser 5.0.3
Ionic Framework    : ionic-angular 3.9.2

System: 系统:

Android SDK Tools : 26.1.1
Node              : v6.12.2
npm               : 4.6.1 
OS                : Linux 4.13

Environment Variables: 环境变量:

ANDROID_HOME : /home/clifford/Android/Sdk

So why I am having an error in that specific service provider compare to other providers which are just the same? 那么,为什么与该相同的其他提供者相比,该特定服务提供者有错误?

Any thoughts? 有什么想法吗?

Appreciate if someone could help. 感谢有人可以帮忙。 Thanks in advance. 提前致谢。

I finally figure it out to solve the problem. 我终于想通了解决问题的方法。 The error occurs when I import the events from ionic-angular . ionic-angular导入事件时发生错误。

So instead of: import { Events } from 'ionic-angular/umd'; 因此,而不是: import { Events } from 'ionic-angular/umd';

Just remove the umd at the end. 只需删除末尾的umd I don't know why it happened because I am using auto import from my vs code. 我不知道为什么会这样,因为我正在使用vs代码中的自动导入功能。

I changed import { Events } from 'ionic-angular/umd'; 我将import { Events } from 'ionic-angular/umd';更改为import { Events } from 'ionic-angular/umd'; to import { Events } from 'ionic-angular'; import { Events } from 'ionic-angular'; . I was using "typescript": "~2.6.2". 我使用的是“打字稿”:“〜2.6.2”。 I tried to change the version of typescript and I have heard that typescript 3.1 can be fix in some cases. 我试图更改打字稿的版本,并且听说打字稿3.1在某些情况下可以解决。 In my case once i went higher than typescript 2.8.0 I started getting other issues related to ionic. 就我而言,一旦我超过打字稿2.8.0,我就开始遇到与离子相关的其他问题。 At the end the above fix works, and I think this is more a ionic framework issue. 最后,上述修复工作成功了,我认为这更多是一个离子框架问题。

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

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