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?
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?
Share Improve this question edited Jan 21, 2018 at 21:59 Carlos Vázquez Losada asked Jan 21, 2018 at 21:35 Carlos Vázquez LosadaCarlos Vázquez Losada 9501 gold badge17 silver badges36 bronze badges 4 |3 Answers
Reset to default 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).
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.
"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
.ts
? Keep in mind that any validjs
file is a validts
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. – Arash Motamedi Commented Jan 21, 2018 at 23:00prisma 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 suck – Dimitri Kopriwa Commented Jul 4, 2024 at 20:52