网站在生产中运行没有任何问题(文件缩小并连接),但是当页面发送到 prerender.js 或 phantom.js 进行快照生成时,我收到错误:
Uncaught Error: [$injector:modulerr] Failed to instantiate module myApp to: Error: [$injector:modulerr] Failed to instantiate module myApp due to: Error: [$injector:nomod] Module 'myApp' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.
https://www.mydomain.io/app/vendor.7240ef6a.js:4
https://www.mydomain.io/app/vendor.7240ef6a.js:3 in d
https://www.mydomain.io/app/vendor.7240ef6a.js:4 in m
https://www.mydomain.io/app/vendor.7240ef6a.js:4 in db
https://www.mydomain.io/app/vendor.7240ef6a.js:3 in g
https://www.mydomain.io/app/vendor.7240ef6a.js:3 in ea
https://www.mydomain.io/app/vendor.7240ef6a.js:3 in da
https://www.mydomain.io/app/vendor.7240ef6a.js:8
https://www.mydomain.io/app/vendor.7240ef6a.js:2 in j
https://www.mydomain.io/app/vendor.7240ef6a.js:2 in fireWith
https://www.mydomain.io/app/vendor.7240ef6a.js:2 in ready
https://www.mydomain.io/app/vendor.7240ef6a.js:1 in g
我必须文件:vendor.js 和 app.js。我的另一个项目具有完全相同的结构(只是文件不同),并且它与相同的 prerender.js 服务器配合良好。
我设法将问题追溯到 jquery.js。但我当时就陷入困境了。似乎 prerender/phanatom.js 以不同的方式加载文件。 A 也使用了 window.prerenderReady = true/false
无济于事。
我正在使用generator-angular-fullstack使用 Angular v1.5.8 和 jQuery v2.2.4
在index.html中,jquery包含在Angular之前。我想知道是否有任何方法可以获得有关问题原因的更详细信息。
最佳答案
如果您的文件加载到 <body>
中,我以前见过这种情况发生。 。在 <body>
中加载脚本使它们异步加载,而脚本可能会以错误的顺序加载。大多数较新的浏览器都能很好地处理这个问题,但 PhantomJS (v2.1.1) 将在加载脚本后立即执行该脚本,无论顺序如何。
我建议尝试在 <head>
中加载这些脚本。 .
关于angularjs - Angular 无法加载仅用于生产的 prerender.js/phantomjs 模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42970536/