【发布时间】:2018-01-21 21:35:13
【问题描述】:
我试图在我的 Angular 5 应用程序中使用一个 .js 文件,该文件仅在 JavaScript 语言中可用,所以我在 TypeScript 中找不到替代方案。
问题是我在 tsconfig.json 中添加了"allowJs": true,但错误仍然存在。我的 tsconfig.json 是:
{
"compileOnSave": false,
"compilerOptions": {
"outDir": "./dist/out-tsc",
"allowJs": true,
"baseUrl": "src",
"sourceMap": true,
"declaration": false,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es5",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2016",
"dom"
]
}
}
错误是:
'<path>/file.js' has unsupported extension. The only supported extensions are '.ts', '.tsx', '.d.ts'.
怎么了?
【问题讨论】:
-
您可以尝试将 checkJs: false 添加到配置中。最好发布错误消息。
-
添加了错误。 checkJs: false 不能解决我的问题
-
你能把那个文件重命名为
.ts吗?请记住,任何有效的js文件也是有效的ts文件,因此更改扩展名不会造成任何问题(可能除了通常的类型警告)并且应该消除错误。
标签: javascript angular tsconfig