【发布时间】:2020-10-01 02:30:50
【问题描述】:
我找不到标准说明来帮助我建立一个有效的 typescript node.js 项目
我遵循了DigitalOcean 和Scotch 之类的流行教程,但没有任何帮助!
- 运行
npm run tsc -- --init以生成评论良好的tsconfig.json。
最初
tsc --init没有生成tsconfig.json,但后来我发现addingtscas the script solved the problem
在项目中添加了一些带有
.ts扩展名的文件。现在,当我运行
tsc以将.ts文件转换为.js文件时 - 我收到以下错误:
错误 TS5014:无法解析文件 'tsconfig.json':JSON 中第 31 位的意外令牌/。
到目前为止我尝试解决的问题:
- installing
typescript npm install typescript --save-dev- I'm already using
cmdinstead ofbash tsc -p tsconfig.json"rootDir": "./src"&&"include": ["src/**/*.ts"]- There is no erroneous comma at the end of the file
当我从自动生成的配置中删除所有 cmets 时,我得到以下 valid JSON:
{
"include": ["src/**/*.ts"],
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"strict": true,
"esModuleInterop": true
}
}
有了这个tsconfig.json - 当我运行tsc 时,我收到以下错误:
error TS5023: Unknown compiler option 'strict'.
error TS5023: Unknown compiler option 'esModuleInterop'.
当我使用 the standard config 并运行 tsc 时,我收到以下错误:
error TS5023: Unknown compiler option 'esModuleInterop'.
error TS5023: Unknown compiler option 'moduleResolution'.
package.json 中的依赖项是:
"devDependencies": {
"@types/express": "^4.17.6",
"tslint": "^6.1.2",
"typescript": "^3.9.5"
},
"dependencies": {
"express": "^4.17.1"
}
环境
npm -v : 6.13.4
node -v : v12.16.1
tsc -v : Version 1.5.3
Windows 10
这是制作打字稿项目的第一步,如果有这么多问题 - 如何制作项目?
是否有一种简单直接的“工作”方式来设置 node.js 打字稿项目?
【问题讨论】:
-
你能分享你的依赖吗?
-
@Baboo_ 分享了问题中的依赖项
-
我建议尝试 deno 而不是 node。 deno.land 根本不需要任何依赖,它原生支持 typescript。
-
@ChrisRollins 节点经过实战考验并且非常成熟!我不建议仅仅因为一个问题而转向新技术,而问题是最基本的问题!
标签: javascript node.js json typescript tsc