'tsconfig.json doesn't care about allowJs
I am trying to use in my Angular 5 application a .js file which is avaible just in JavaScript language, so I can't find an alternative in TypeScript.
The problem is that I have added the "allowJs": true in my tsconfig.json, but the error is still active. My tsconfig.json is:
{
"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"
]
}
}
The error is:
'<path>/file.js' has unsupported extension. The only supported extensions are '.ts', '.tsx', '.d.ts'.
Whats wrong?
Solution 1:[1]
{
"compilerOptions": {
"outDir": "./built",
"allowJs": true,
}
}
You can only run tsc to compile your js file.
if u run tsc file.js, it will throw an error.
Because if you run tsc, it will find the nearest config file, but if you run tsc file.js, it will run depending on the default file(allowJs:false? ignore tsconfig.json).
Solution 2:[2]
"AllowJs" option allows you To accept js files as input for ts files.
You can migrate your js file to typescript, follow this link for more details: https://www.typescriptlang.org/docs/handbook/migrating-from-javascript.html
Solution 3:[3]
allowJS: Allow JavaScript files to be imported inside your project, instead of just .ts and .tsx files. (Please take a look into the official docs, which should be available during 2022)
The problem is that I have added the "allowJs": true in my tsconfig.json, but the error is still active.
That means your tsconfig.json is not referenced during compilation.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | mth khaled |
| Solution 3 | VimNing |
