最近新安装了 postgres,同时安装了 pgAdmin 4,但是遇到了无法启动的问题。
问题描述:
打开 pgAdmin 4 ,弹出浏览器页面时一直处于转圈圈加载的页面
使用浏览器开发者工具检查,发现报错信息
Refused to execute script from 'http://127.0.0.1:54943/static/vendor/require/require.min.js?ver=42800' because its MIME type ('text/plain') is not executable, and strict MIME type checking is enabled.
Refused to execute script from 'http://127.0.0.1:54943/static/js/generated/vendor.main.js?ver=42800' because its MIME type ('text/plain') is not executable, and strict MIME type checking is enabled.
Refused to execute script from 'http://127.0.0.1:54943/static/js/generated/vendor.others.js?ver=42800' because its MIME type ('text/plain') is not executable, and strict MIME type checking is enabled.
Refused to execute script from 'http://127.0.0.1:54943/static/js/generated/pgadmin_commons.js?ver=42800' because its MIME type ('text/plain') is not executable, and strict MIME type checking is enabled.
解决方案:
从报错信息可以看出,浏览器没有将 require.min.js、vendor.main.js、vendor.others.js、pgadmin_commons.js 这几个文件解释为 JavaScript,所以无法执行这些脚本,他们的响应头里面 Content-Type 是 text/plain。可能是因为 注册表被破坏,把扩展名为 js 的文件类型注册为 ‘text/plain’
方法一:
打开注册表: 计算机\HKEY_CLASSES_ROOT\.js\
修改 Content Type
选项的配置,将 text/plain 修改为 text/javascript 或 application/javascript
方法二:
修改 postgres 安装目录/pgAdmin 4/web
路径下的 config.py
文件
在文件末尾添加
import mimetypes
mimetypes.add_type('application/javascript', '.js')
方法三:
修改 postgres 安装目录/pgAdmin 4/web
路径下的 config.py
文件 第179行
将 X_CONTENT_TYPE_OPTIONS = “nosniff” 修改为 X_CONTENT_TYPE_OPTIONS = ""
在方法二、三中,文本编辑器没有用管理员模式运行的话,无法直接保存对 config.py
文件的修改,可以考虑
- 先用管理员模式运行文本编辑器,然后在编辑器里面打开该文件
- 将该文件复制到其他路径,修改后再替换回该目录
最后,在右下角托盘右击 pgAdmin 4 图标,shut down server,再重新打开 pgAdmin 4