Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 502
Carlos Vázquez Losada Avatar asked Apr 07 '26 10:04

Carlos Vázquez Losada


1 Answers

{
  "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).

like image 152
YinPeng.Wei Avatar answered Apr 09 '26 01:04

YinPeng.Wei