第三方图书馆“cordova-plugin-ms-azure-mobile-apps”在我的Ionic 2应用程序中无法识别 [英] 3rd Party Library “cordova-plugin-ms-azure-mobile-apps” not getting recognized in my Ionic 2 app

查看:140
本文介绍了第三方图书馆“cordova-plugin-ms-azure-mobile-apps”在我的Ionic 2应用程序中无法识别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在过去2天内无处不在(并浏览各种网站上的过去的论坛主题)之后,没有解决方案,我作为最后的手段在这里发布。我知道每个人都很忙,但这让我很难过。



我已经尝试过一切可能从多次创建应用程序到一次添加一个库然后运行和制作确定它正在工作然后添加另一个库然后运行应用程序...



一切都很好,直到我添加 cordova-plugin-ms-azure-mobile-应用在我的应用中。我使用以下命令:



离子插件添加cordova-plugin-ms-azure-mobile-apps --save



这会在我的config.xml中添加一个条目。



然后当我尝试引用它来导入WindowsAzure类时在我的TypeScript文件中,intelisense不会将该库作为选项提供给其他库(如ionic-native,rxjs,momentjs等)。我也将它添加到declarations.d.ts中,但也没有帮助。但我仍然继续手动导入它,如下所示:



从'cordova-plugin-ms-azure-mobile-apps'导入{WindowsAzure};



VS Code不抱怨和离子服务 当我运行命令时,也不会抱怨(在构建代码时)。但是,当应用尝试在浏览器(Chrome)中启动时,我收到运行时错误,说无法找到模块cordova-plugin-ms-azure-mobile-apps



为了确保,我尝试使用离子运行android在我连接的Android手机上运行它。在手机上,它也会尝试启动应用程序(我按照预期的那样获得启动画面)然后屏幕全白并保持原样。将Android手机连接到笔记本电脑后,我尝试在Chrome中进行检查。它显示相同的无法找到模块cordova-plugin-ms-azure-mobile-apps 错误为 Uncauth Error
请注意,我在添加(并在代码中使用)此库之前在手机上运行该应用程序,它就像一个魅力。



尝试另一种方式,我使用以下命令将浏览器添加为平台:



离子平台添加浏览器



然后使用以下命令运行应用程序:



离子运行浏览器



相同的行为。它没有启动。



为了尝试更多,我使用命令添加了库:



npm install cordova-plugin-ms-azure-mobile-apps --save



然后它被添加到我的应用程序的package.json中依赖然后当我尝试在导入中的TypeScript文件中引用它时,我将库作为InteliSense选项。但最终结果仍然是相同的。我仍然得到运行时间错误无法在Chrome浏览器中找到模块cordova-plugin-ms-azure-mobile-apps和Android手机上的白色空白屏幕。



我将非常感谢如果你能帮我解决这个问题。我迫切需要帮助,因为我已经用尽了所有选择和所有思考能力。 :(



PS - 只有当我尝试使用Ionic 2应用程序时才会发生这种情况。否则,当我使用HTML / JavaScript / Cordova / Node.js时,它会正常工作一个单独的项目。:皱眉:



谢谢。

解决方案

最后,让它工作!感谢微软的支持!



我认为,在TypeScript世界中,这不是最好的解决方案,但这是让它工作的唯一方法。 / p>

因此,我所要做的就是使用 cordova-plugin-ms-azure-mobile中的 WindowsAzure 命名空间-apps 作为常规普通旧JavaScript变量,而不是执行导入



也就是说,而不是从'cordova-plugin-ms-azure-mobile-apps'导入WindowsAzure:



导入{WindowsAzure};



我在所有导入之后和 @Component class and /或 @Injectable 服务/提供者类,如:



```

 从'...'导入{...}; 

声明var WindowsAzure:any;

@Injectable
导出类... {
客户:任何;
....
构造函数或yourMethod(...){
this.client = new WindowsAzure.MobileServiceClient('http://YourAzureMobileApp.azurewebsites.net');
}
....
....
//你的逻辑
}

```



所以,显然,如果你的第三方图书馆没有得到常规认可,在Ionic 2中导入声明然后您应该尝试以旧的JavaScript方式使用它。



这就是我最终解决的问题花2天。 :(



希望这有助于节省时间。


After looking everywhere (and going through the past forum topics on all sorts of websites) for the last 2 days and no solution, I am posting here as a last resort. I understand everybody is busy but this is killing me.

I have tried everything possible from creating the app from scratch multiple times to adding one library at a time then run and make sure it's working then add another library and then run the app...

Everything is good until I add "cordova-plugin-ms-azure-mobile-apps" in my app. I am using the following command:

ionic plugin add cordova-plugin-ms-azure-mobile-apps --save

This adds an entry to my config.xml.

Then when I try to refer to it for importing "WindowsAzure" class in it into my TypeScript file, the intelisense doesn't give that library as an option as it would give for other libraries (like ionic-native, rxjs, momentjs, etc.). I added it to "declarations.d.ts" as well but that also didn't help.But I still went ahead and imported it manually like below:

import { WindowsAzure } from 'cordova-plugin-ms-azure-mobile-apps';

VS Code doesn't complain and the "ionic serve" also doesn't complain (while building the code) when I run the command. However, when the app tries to launch in browser (Chrome) I get a Runtime Error saying Cannot find module "cordova-plugin-ms-azure-mobile-apps".

Just to make sure, I tried to run it on my connected Android Phone using "ionic run android". On the phone also, it tries to launch the app (I get the splash screen as it is supposed to) then the screen goes all white and stays like that. I tried to inspect in Chrome after connecting my Android phone to my laptop. It showed the same "Cannot find module "cordova-plugin-ms-azure-mobile-apps" error as "Uncauth Error". Please note, I ran the app on phone before adding (and using it in the code) this library and it worked like a charm.

To try another way, I added browser as a platform using the command:

ionic platform add browser

Then run the app using the command:

ionic run browser

Same behavior. It's not launching.

To try more, I added the library using command:

npm install cordova-plugin-ms-azure-mobile-apps --save

Then it got added to my app's package.json in "dependencies" section. Then when I tried to refer to it in my TypeScript file in "import" I got the the library as InteliSense option. But the end result is still the same. I still get Runtime Error "Cannot find module cordova-plugin-ms-azure-mobile-apps" in the Chrome browser and a white blank screen on Android phone.

I would highly appreciate if you could please help me to fix this. I desperately need help as I have exhausted all my options and all my thinking capabilities. :(

P.S. - this is happening only when I try in Ionic 2 app. Otherwise, it works absolutely fine when I use HTML/JavaScript/Cordova/Node.js in a separate project. :frowning:

Thank you.

解决方案

Finally, got it working! Thanks for Microsoft support!

Not the best solution, I think, in the world of TypeScript but that's the only way to make it work.

So, all I had to do was to use the "WindowsAzure" namespace from "cordova-plugin-ms-azure-mobile-apps" as a regular plain old JavaScript variable instead of doing an "import".

That is, instead of importing WindowsAzure as:

import { WindowsAzure } from 'cordova-plugin-ms-azure-mobile-apps';

I declared it as a regular JavaScript object after all the "imports" and before "@Component" class and/or "@Injectable" service/provider class, as:

```

import { ... } from '...';

declare var WindowsAzure: any;

@Injectable
export class ... {
    client: any;
    ....
    constructor or yourMethod(...) {
        this.client = new WindowsAzure.MobileServiceClient('http://YourAzureMobileApp.azurewebsites.net');
    }
    ....
    ....
    //Your logic
}

```

So, apparently, in Ionic 2 if your third party library is not being recognized with regular "import" statement then you should try to use it in the old JavaScript way.

It was that simple a solution on something where I ended up spending 2 days. :(

Hope this helps somebody save their time.

这篇关于第三方图书馆“cordova-plugin-ms-azure-mobile-apps”在我的Ionic 2应用程序中无法识别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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