gpt4 book ai didi

typescript - 类型错误 [ERR_UNKNOWN_FILE_EXTENSION] : Unknown file extension ".ts" on Visual Studio Code

转载 作者:行者123 更新时间:2023-12-03 16:33:06 29 4
gpt4 key购买 nike

我一直在对一些代码进行单元测试,但似乎无处可去,我收到了关于未知文件扩展名的错误(之前,我收到了有关如何无法识别某些类型的错误)。
这是我的 package.json:

{
"name": "cgt-core-engine-mv",
"description": "API container for other CGT plugins",
"version": "1.01.03",
"author": "CG-Tespy",
"repository": {
"type": "git",
"url": "https://github.com/CG-Tespy/CGT_CoreEngine_MV"
},
"scripts": {
"build": "tsc & (rollup -c)",
"test": "mocha -r ts-node/register Test/**/*.ts"
},
"dependencies": {},
"devDependencies": {
"@types/chai": "^4.2.12",
"@types/mocha": "^8.0.0",
"@types/sinon": "^9.0.4",
"chai": "^4.2.0",
"mocha": "^8.0.1",
"rollup": "^2.00.1",
"rollup-plugin-node-resolve": "^5.2.0",
"rollup-pluginutils": "^2.8.2",
"sinon": "^9.0.2",
"ts-node": "^8.10.2",
"typescript": "^3.9.6"
},
"type": "module"
}
这是我的 tsconfig.json:
{
"compilerOptions": {
"target": "es5",
"module": "CommonJS",
"esModuleInterop": true,

"sourceMap": false,
"downlevelIteration": true,
},
"include": ["_MainSource/**/*", "Tests/**/*", "@typeDefs/**/*"],
}
我真的不知道这是从哪里来的。我有一个单独的项目,我能够很好地对事物进行单元测试,并且没有给我任何错误。它的 package.json:
{
"name": "unittesting",
"version": "1.0.0",
"description": "For practicing unit-testing",
"main": "main.js",
"scripts": {
"test": "mocha -r ts-node/register test/**/*.ts"

},
"author": "",
"license": "ISC",
"devDependencies": {
"@types/chai": "^4.2.11",
"@types/mocha": "^8.0.0",
"chai": "^4.2.0",
"mocha": "^8.0.1",
"ts-node": "^8.10.2",
"typescript": "^3.9.7"
},
"type": "module"
}
它的 tsconfig:
{
"compilerOptions": {
/* Basic Options */

"target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
"module": "CommonJS", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */

"esModuleInterop": true,

},
"include": ["src/**/*", "tests/**/*"],
}
什么可能导致这个问题?我已经尝试了建议 here ,但它不起作用(即使在查看链接的 Github 问题之后)。

最佳答案

您是否尝试从 package.json 文件中删除 "type": "module"

关于typescript - 类型错误 [ERR_UNKNOWN_FILE_EXTENSION] : Unknown file extension ".ts" on Visual Studio Code,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63386054/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com