【发布时间】:2020-06-04 19:17:10
【问题描述】:
我是 nodejs 和 vscode 的新手……我有两个文件:entry.js 和 /utils/database.js。
当我运行 node entry.js 时,我得到了我期望的小日志记录 (SSSS)。我想在调试模式下运行它,以便我可以构建它,但是当我点击左侧调试中的“运行”时,我得到:
SyntaxError: Unexpected token import
系统: Ubuntu 18.04
编辑:Visual Studio Code 1.45.1 版
node --version: v13.11.0npm --version: 6.13.7
package.json:
{
"type": "module",
"name": "node_load_test",
"version": "1.0.0",
"description": "",
"main": "entry.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"mysql": "^2.18.1"
}
}
launch.json:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch root Program",
"skipFiles": ["<node_internals>/**"],
"program": "${workspaceFolder}/entry.js"
},
{
"type": "node",
"request": "launch",
"name": "Launch 6 Program",
"skipFiles": ["<node_internals>/**"],
"program": "${workspaceFolder}/6/entry.js"
}
]
}
utils/database.js:
import mysql from "mysql";
export const pool = mysql.createPool({
connectionLimit: 100,
host: "localhost",
user: "root",
password: "password",
database: "no_replicate",
});
entry.js:
"use strict";
import { pool } from "./utils/database.js";
pool.end(function (err) {
if (err) {
return console.log("error:" + err.message);
}
console.log("Close the database connection.");
});
pool.getConnection(function (err, connection) {
// execute query
// ...
console.log("SSSS");
});
任何帮助都会让我开心。谢谢
【问题讨论】:
标签: mysql node.js debugging ecmascript-6 visual-studio-code