mysql - 我在构造函数中创建了一个连接,但在保存组件时出现错误
问题描述
我已经正确导入了mysql。这是我的代码,其中我在构造函数中声明了连接。
import mysql from 'mysql';
export class StepForm extends Component {
constructor() {
super();
this.state ={
step: 1,
// welcome
qNumber:1,
accountNumber:'',
amount:'',
txNumber:1,
postArray : []
}
const connection = mysql.createConnection({
host: 'localhost',
port: 3306,
user: 'root',
password: 'whil',
database: 'qany'
});
connection.connect();
console.log(connection);
}
保存组件时遇到错误,
TypeError: Net.createConnection is not a function
Connection.connect
C:/react_programs/q_any/node_modules/mysql/lib/Connection.js:74
71 | this._connectCalled = true;
72 |
73 | // Connect either via a UNIX domain socket or a TCP socket.
> 74 | this._socket = (this.config.socketPath)
| ^ 75 | ? Net.createConnection(this.config.socketPath)
76 | : Net.createConnection(this.config.port, this.config.host);
77 |
应该做什么?
解决方案
推荐阅读
- python - 我正在尝试在 python/pandas 中将多行组合成单行
- javascript - '$' 未在 JavaScript 中定义
- ckeditor - 如何允许通过 URL 插入图像但不允许上传?
- nosql - 有没有办法强制在 Oracle NoSQL 数据库的查询中首先使用特定的二级索引?
- python - 无法在 try-except 结构中编译并返回 Python 函数
- node.js - 为什么我无法访问此 node.js 应用程序中的 HTTP 调用?
- android - 每当我尝试在 Firestore 上打开特定文档时,Firestore 控制台就会打开。仅在我单击特定文档时发生
- python - 将元组转换为熊猫数据框
- java - 如何使用 URI 从 Java 桌面应用程序打开默认文本/呼叫/地图应用程序?
- azure-vpn - Azure VPN 设备连接到 Azure VM(域控制器)的问题