我想连接到我的数据库。我在论坛中搜索,发现对此有用的工具是mysql2。我试图在项目中编写一些代码,但无法正常工作。您有关于此节点的TypeScript逐步配置的任何教程吗?
main.ts的片段
import { mysql } from "mysql2"
const connection = mysql.createConnection({
host: 'localhost',
user: 'root',
database: 'test'
});
终端输出
WARNING in ../node_modules/mysql2/lib/helpers.js
Module not found: Error: Can't resolve 'cardinal' in 'D:\Native Script\ooooooo\node_modules\mysql2\lib'
@ ../node_modules/mysql2/lib/helpers.js
@ ../node_modules/mysql2/lib/parsers/binary_parser.js
@ ../node_modules/mysql2/lib/commands/execute.js
@ ../node_modules/mysql2/lib/commands sync ^\.\/.*\.js$
@ ../node_modules/mysql2/lib/commands/index.js
@ ../node_modules/mysql2/lib/connection.js
@ ../node_modules/mysql2/index.js
@ ./main.ts
ERROR in ../node_modules/mysql2/lib/connection.js
Module not found: Error: Can't resolve 'net' in 'D:\Native Script\ooooooo\node_modules\mysql2\lib'
@ ../node_modules/mysql2/lib/connection.js 3:12-26
@ ../node_modules/mysql2/index.js
@ ./main.ts
ERROR in ../node_modules/mysql2/lib/server.js
Module not found: Error: Can't resolve 'net' in 'D:\Native Script\ooooooo\node_modules\mysql2\lib'
@ ../node_modules/mysql2/lib/server.js 3:12-26
@ ../node_modules/mysql2/index.js
@ ./main.ts
ERROR in ../node_modules/mysql2/lib/connection.js
Module not found: Error: Can't resolve 'timers' in 'D:\Native Script\ooooooo\node_modules\mysql2\lib'
@ ../node_modules/mysql2/lib/connection.js 5:15-32
@ ../node_modules/mysql2/index.js
@ ./main.ts
ERROR in ../node_modules/mysql2/lib/connection.js
Module not found: Error: Can't resolve 'tls' in 'D:\Native Script\ooooooo\node_modules\mysql2\lib'
@ ../node_modules/mysql2/lib/connection.js 4:12-26
@ ../node_modules/mysql2/index.js
@ ./main.ts