[英]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/'
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.你在这里有两个问题。
/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. 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.