由于Angular Universal中的Zone.js,服务器渲染停止工作.怎么修? [英] Due to Zone.js in Angular Universal server rendering stops working. How to fix?

查看:167
本文介绍了由于Angular Universal中的Zone.js,服务器渲染停止工作.怎么修?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的数据请求中,我返回了简单的JSON而不连接到数据库时,Angular Universal中的服务器渲染工作正常.

When in my requests for data I return simple JSON without connection to database the server rendering in Angular Universal works fine.

但是,我发现如果我没有适当版本的Zone.js,对MySQL数据库的请求将不会进行. 我遇到以下错误:

However I have found that requests to MySQL database is not going if I don't have a proper version of Zone.js. I had the following error:

TypeError: Cannot read property 'on' of undefined
        at Protocol._enqueue (/Applications/MAMP/htdocs/Angular2/myproject/node_modules/mysql/lib/protocol/Protocol.js:152:5)
...

我也注意到自己有一个警告:

Also I payed attention that I had a warning:

angular2-universal@2.1.0-rc.1 requires a peer of zone.js@~0.6.21 but none was installed. 

所以我安装了正确的Zone.js:

So I installed proper Zone.js:

npm install zone.js@0.6.21

然后我开始从MySQL接收数据.

and I started receiving data from MySQL.

但是!此时服务器渲染停止工作!我只看到:

BUT! At this point server rendering stops working! I only see:

<!--template bindings={}-->

在HTML模板中.

我回过头来返回不连接MySQL的JSON,发现即使在这种情况下,服务器渲染也无法正常工作.

I moved back to return a JSON without connection to MySQL and have found that even at this case server rendering is not working.

因此,我对此进行了一些尝试,发现如果我使用命令:

So I have played a little with this and have found that if I use command:

npm install zone.js

然后当我返回不连接数据库的JSON时,服务器渲染正常工作,但是如果我尝试连接到MySQL,则会发生原始错误.

then server rendering works properly when I return JSON without connection to database, but if I try to connect to MySQL then original error occurs.

所以现在我可以使用服务器渲染,也可以不使用服务器渲染连接到MySQL.不是服务器渲染和与数据库的有效连接.

So now I have either working server rendering or connection to MySQL without server rendering. Not server rendering and working connection to database.

如果有人知道应该怎么做,我将不胜感激.谢谢你.

If anyone knows what should be done I'll appreciate the help. Thank you.

推荐答案

我找到了解决方案.就我而言,该问题已通过以下命令解决:

I have found the solution. In my case the issue was resolved by the command:

npm install zone.js@latest

现在,我可以向MySQL发出请求,并且可以进行服务器渲染,并且可以在HTML模板中看到所有数据.

Now I can do the requests to MySQL and also I have a server rendering and can see all the data in my HTML-template.

这篇关于由于Angular Universal中的Zone.js,服务器渲染停止工作.怎么修?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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