简体   繁体   English

服务器以“text/html”的非 JavaScript MIME 类型响应 - 节点

[英]The server responded with a non-JavaScript MIME type of "text/html" - Node

I'm getting this error while trying to create/import a Client instance to connect to a local DB, (PGADMIN).我在尝试创建/导入客户端实例以连接到本地数据库 (PGADMIN) 时遇到此错误。

import {Client} from '/node_modules/pg/lib/'

Error错误

My Directory我的目录

Last part of my index.html我的 index.html 的最后一部分

I've tried many types of urls but I can't get it done.我尝试了多种类型的网址,但无法完成。 So I'm asking for help.所以我在寻求帮助。

Also, I've tried: const {Client} = require('pg') , but I get the " Uncaught ReferenceError: require is not defined"另外,我试过: const {Client} = require('pg') ,但我得到“未捕获的 ReferenceError: require is not defined”

Thanks.谢谢。

You have two problems here.你在这里有两个问题。

  1. /node_modules/pg/lib/ is going to resolve to an HTML document listing the files in that directory. /node_modules/pg/lib/将解析为列出该目录中文件的 HTML 文档。 You can only import a JS file.您只能导入一个 JS 文件。
  2. Any library that allows you to directly connect to a postgresql database is going to depend on APIs provided by Node.js and which are not available in a browser, so even if you imported the correct URL, it still wouldn't work.任何允许您直接连接到 postgresql 数据库的库都将依赖于 Node.js 提供的 API,而这些 API 在浏览器中不可用,因此即使您导入了正确的 URL,它仍然无法正常工作。

Connect to the database from server-side code and use it to provide the client with a webservice that you can access with Ajax.从服务器端代码连接到数据库,并使用它为客户端提供可以使用 Ajax 访问的 Web 服务。


Also, I've tried: const {Client} = require('pg') , but I get the "Uncaught ReferenceError: require is not defined"另外,我试过: const {Client} = require('pg') ,但我得到“未捕获的 ReferenceError:需要未定义”

Browsers don't have native support for CommonJS modules.浏览器没有对 CommonJS 模块的原生支持。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 服务器以非 JavaScript MIME 类型的“应用程序/节点”响应 - The server responded with a non-JavaScript MIME type of “application/node” Vue.js 3 - “加载模块脚本失败:服务器以非 JavaScript MIME 类型“text/html”响应 - Vue.js 3 - “Failed to load module script: The server responded with a non-JavaScript MIME type of ”text/html" Flask:加载模块脚本失败:服务器以“text/html”的非 JavaScript MIME 类型响应 - Flask: Failed to load module script: The server responded with a non-JavaScript MIME type of “text/html” 加载模块脚本失败:服务器以非 JavaScript、CSS MIME 类型“text/x-scss”响应 - Failed to load module script: The server responded with a non-JavaScript, CSS MIME type of “text/x-scss” 无法加载模块脚本:服务器以“text/plain”的非 JavaScript MIME 类型响应 - Failed to load module script: The server responded with a non-JavaScript MIME type of "text/plain" 服务器以“application/octet-stream”的非 JavaScript MIME 类型响应 每个 HTML 对模块脚本强制执行严格的 MIME 类型检查 - The server responded with a non-JavaScript MIME type of "application/octet-stream" Strict MIME type checking is enforced for module scripts per HTML 加载模块脚本失败:服务器以“text/plain”的非 JavaScript MIME 类型响应。 对模块强制执行严格的 MIME 类型检查 - Failed to load module script: The server responded with a non-JavaScript MIME type of "text/plain". Strict MIME type checking is enforced for module 加载模块脚本失败:服务器以“text/plain”的非 JavaScript MIME 类型响应。 严格的 MIME 类型检查 i - Failed to load module script: The server responded with a non-JavaScript MIME type of "text/plain". Strict MIME type checking i 加载模块脚本失败:服务器以非 JavaScript MIME 类型“”响应。 强制执行严格的 MIME 类型检查 - Failed to load module script: The server responded with a non-JavaScript MIME type of “”. Strict MIME type checking is enforced 加载模块脚本失败:服务器响应非 JavaScript MIME 类型“” - Failed to load module script: The server responded with a non-JavaScript MIME type of ""
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM