Car*_*ada 11 javascript tsconfig angular
我试图在我的 Angular 5 应用程序中使用一个 .js 文件,该文件仅以 JavaScript 语言提供,所以我在 TypeScript 中找不到替代方案。
问题是我已"allowJs": true在 tsconfig.json 中添加了 ,但错误仍然存在。我的 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"
]
}
}
Run Code Online (Sandbox Code Playgroud)
错误是:
'<path>/file.js' has unsupported extension. The only supported extensions are '.ts', '.tsx', '.d.ts'.
Run Code Online (Sandbox Code Playgroud)
怎么了?
Yin*_*Wei 10
{\n "compilerOptions": {\n "outDir": "./built",\n "allowJs": true,\n }\n}\nRun Code Online (Sandbox Code Playgroud)\n\n你只能运行tsc来编译你的js文件。
如果你运行tsc file.js,它会抛出一个错误。
因为如果你运行tsc,它会找到最近的配置文件,但如果你运行tsc file.js,它将根据默认文件运行(allowJs:false\xef\xbc\x8c 忽略 tsconfig.json)。
“AllowJs”选项允许您接受 js 文件作为 ts 文件的输入。
您可以将 js 文件迁移到 typescript,请点击此链接了解更多详细信息: https ://www.typescriptlang.org/docs/handbook/migration-from-javascript.html
| 归档时间: |
|
| 查看次数: |
26405 次 |
| 最近记录: |