debugging - VSCode 内部人员节点调试器启动 src 文件而不是构建
问题描述
因此,我有一个非常整洁的项目,并进行了一些非常简洁的调试,该调试一直有效,但经过太长时间的中断后,现在我似乎无法使其正常工作。就像我在调试选项卡中注意到的一样
Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
(Use `node --trace-warnings ...` to show where the warning was created)
/home/inaba/Programming/Lewd/packages/main-site/src/index.js:1
import express from "express";
这是我的launch.json,它一直有效
{
"type": "node",
"request": "launch",
"name": "Launch Main App",
"preLaunchTask": "npm: build",
"program": "src/index.js",
"sourceMaps": true,
"outFiles": [
"dist/**/*.js"
],
"envFile": "${workspaceFolder}/../../.env",
"runtimeArgs": [
"--require=dotenv/config"
]
}
那么到底是什么?据我所知,我做的事情对吗?
解决方案
尝试 require() 而不是 import 语句
在这里引用节点文档:
import 语句只允许在 ES 模块中使用。有关 CommonJS 中的类似功能,请参阅 import()。
https://nodejs.org/api/esm.html#esm_import_statements
这里有一些详细的上下文:Using Node.js require vs. ES6 import/export
推荐阅读
- react-native - React native appstate 用于检查用户在线和离线
- excel - 满足某些条件时删除工作表
- c# - WebRequest NET Core 3.1 中的自定义标头
- swift - NSTextList 格式化
- matlab - 在 Matlab 的表格中使用 \pm Latex 符号
- java - 如何使用 Intent 以字节数组形式可视化文件?
- python - Django Rest Framework如何在models.CharField上设置error_messages
- git - 我如何告诉 git 在运行 git merge 时它不能自动合并分支?
- jolie - 换一个词访问 Jolie 中的 json 数据
- python - 使用 matplotlib 从文件中提取值以创建条形图