close

How to import js-modules into TypeScript file?

Hello Guys, How are you all? Hope You all Are Fine. Today we are going to learn How to import js-modules into TypeScript file? in javascript. So Here I am Explain to you all the possible methods here.

Without wasting your time, Let’s start This Article.

How to import js-modules into TypeScript file ?

  1. How to import js-modules into TypeScript file ?

    to import js-modules into TypeScript file I've been facing this problem for long but what this solves my problem Go inside the tsconfig.json and add the following under compilerOptions
    { "compilerOptions": { ... "allowJs": true ... } }

  2. How to import js-modules into TypeScript file ?

    to import js-modules into TypeScript file I've been facing this problem for long but what this solves my problem Go inside the tsconfig.json and add the following under compilerOptions
    { "compilerOptions": { ... "allowJs": true ... } }

Method 1

2021 Solution

If you’re still getting this error message:

TS7016: Could not find a declaration file for module './myjsfile'

Then you might need to add the following to tsconfig.json

{
  "compilerOptions": {
    ...
    "allowJs": true,
    "checkJs": false,
    ...
  }
}

This prevents typescript from trying to apply module types to the imported javascript.

Method 2

I’ve been facing this problem for long but what this solves my problem Go inside the tsconfig.json and add the following under compilerOptions

{
  "compilerOptions": {
      ...
      "allowJs": true
      ...
  }
}

Summery

It’s all About this article. Hope all method helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which method worked for you? Thank You.

Leave a Comment