tsconfig.json doesn't care about allowJs
Asked Answered
I

3

11

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?

Incursion answered 21/1, 2018 at 21:35 Comment(4)
You can try to add checkJs: false to the config. And its better to post the error message.Fecund
Error added. checkJs: false doesn't solve my problemFriulian
Can you rename that file to .ts? Keep in mind that any valid js file is a valid ts file as well, so changing the extension shouldn't cause any trouble (other than the usual type warnings perhaps) and should get rid of the error.Tungstite
I have js file generate with prisma generate client it is in my project but not on git, it is necessary since I use yarn4 that it is within the scope that I can import. I also have the same issue when using allowJs: true it can be imported, but checkJs: false does not work and I don't know what to do because I can't use annotation in generated file. It suckBrand
M
10
{
  "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).

Maynardmayne answered 15/3, 2019 at 8:36 Comment(0)
S
1

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.

Selimah answered 22/3, 2022 at 4:4 Comment(0)
L
-1

"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

Licking answered 21/1, 2018 at 22:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.