离子未捕获错误:找不到模块“."导入服务提供者时 [英] Ionic Uncaught Error: Cannot find module "." when importing a service provider
问题描述
我正在尝试导入我刚刚从 ionic 应用程序的最新分支中提取后创建的新服务提供者.
当我尝试导入这行代码时:
import { AuthServiceProvider } from '../providers/auth-service'
在 app.module.ts 中,我总是收到一条错误消息:
<块引用>未捕获的错误:找不到模块."在 webpackMissingModule (index.js:3)在 e.code (index.js:3)在对象<匿名>(index.js:9)在 __webpack_require__(引导程序 62d6a5897825ac327001:54)在 Object.690 (slide.transition.ts:67)在 __webpack_require__(引导程序 62d6a5897825ac327001:54)在 Object.495 (main.js:1885)在 __webpack_require__(引导程序 62d6a5897825ac327001:54)在 Object.487 (notification-api.ts:6)在 __webpack_require__(引导程序 62d6a5897825ac327001:54)
但请注意,我还从我的提供商那里导入了另一项运行良好的服务.
下面是我的 auth-service.ts 的代码.
import { HttpClient } from '@angular/common/http';从@angular/core"导入{可注射};从'ionic-angular/umd'导入{事件};/*为 AuthServiceProvider 提供程序生成的类.有关提供商的更多信息,请参阅 https://angular.io/guide/dependency-injection和角度DI.*/@Injectable()导出类 AuthServiceProvider {公共 isLoggedIn = false;构造函数(公共 http: HttpClient,私人活动:活动){console.log('Hello AuthServiceProvider Provider');events.subscribe('user:logged-in', (user) => {this.isLoggedIn = true;console.log('欢迎', 用户);});}}
我不会在我的 app.module.ts 中显示我的代码,因为它被导入插件和其他提供者轰炸.
这是我的离子信息
cli 包:(/usr/lib/node_modules)@ionic/cli-utils:1.19.2离子(离子 CLI):3.20.0
全局包:
cordova (Cordova CLI) : 8.0.0
本地包:
@ionic/app-scripts : 3.1.8Cordova 平台:android 6.3.0 浏览器 5.0.3离子框架:离子角3.9.2
系统:
Android SDK 工具:26.1.1节点:v6.12.2npm : 4.6.1操作系统:Linux 4.13
环境变量:
ANDROID_HOME :/home/clifford/Android/Sdk
那么为什么我在那个特定的服务提供者中与其他相同的提供者相比有错误?
有什么想法吗?
感谢有人能提供帮助.提前致谢.
我终于想通了,解决了问题.当我从 ionic-angular
events 时发生错误>.
所以代替:import { Events } from 'ionic-angular/umd';
只需删除最后的 umd.我不知道为什么会这样,因为我使用的是从我的 vs 代码中自动导入.
I am trying to import a new service provider that I just created after pulling from the latest branch in my ionic app.
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:
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.
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.
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
.
So instead of: import { Events } from 'ionic-angular/umd';
Just remove the umd at the end. I don't know why it happened because I am using auto import from my vs code.
这篇关于离子未捕获错误:找不到模块“."导入服务提供者时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!