【发布时间】:2020-12-08 18:22:15
【问题描述】:
我最近在我的 NodeJS 项目中的某个 TypeScript 文件中添加了 __DEV__。在 VSCode 中,这不会被标记为错误。
但是,当我运行项目时,我立即得到错误
error TS2304: Cannot find name '__DEV__'.
我尝试将/* global __DEV__ */ 添加到文件顶部。错误仍然存在。
我尝试在declare var __DEV__: boolean; 的位置添加一个global.d.ts 文件。错误仍然存在。
这是我的 tsconfig:
{
"compilerOptions": {
"target": "es6",
"lib": [
"es2017","es2015","dom","es6"
],
"module": "commonjs",
"outDir": "./",
"sourceMap": true,
"esModuleInterop": true,
"strict": false,
"resolveJsonModule": true,
"downlevelIteration": true
},
"include": [
"**.ts"
],
"exclude": [
"node_modules"
]
}
编辑: 该项目通过 VSCode 中的 launch.json 文件启动。以下是它的内容:
{
"version": "0.2.0",
"configurations": [
{
"name": "Current TS File",
"type": "node",
"request": "launch",
"args": ["${relativeFile}"],
"runtimeArgs": ["--nolazy", "-r", "ts-node/register", "--max-old-space-size=32768"],
"cwd": "${workspaceRoot}",
"protocol": "inspector",
"internalConsoleOptions": "openOnSessionStart",
"console": "integratedTerminal",
"stopOnEntry": false,
"skipFiles": [
"${workspaceFolder}/node_modules/**/*.js",
"<node_internals/**/*.js"
]
}
]
}
【问题讨论】:
-
您遗漏了最重要的信息。 如何您正在运行该项目?你向
ts-node传递什么参数?此外,您的tsconfig.json存在语法错误,因为它不是有效的 JSON,这将导致某些工具失败。 -
@AluanHaddad 查看编辑。
tsconfig.json现在应该是有效的 json。
标签: node.js typescript ts-node