Webpack used typeScript, to install js-cookie and introduced it in .ts but said that the module could not be found

install: npm i js-cookie-- save
Import: import Cookies from "js-cookie";
restart: npm run dev

error in. / src/utils/cookie.ts
[tsl] error

  TS7016: Could not find a declaration file for module "js-cookie". "C:\\\\jiGouHouTai\node_modules\js-cookie\src\js.cookie.js" implicitly has an "any" type.

error in. / src/utils/Cookie.ts

[tsl] reported an error

  TS7016: Could not find a declaration file for module "js-cookie". "C:\\\\jiGouHouTai\node_modules\js-cookie\src\js.cookie.js" implicitly has an "any" type.

the package may have been misplaced

npm install-- save @ types/js-cookie

Discussion on

github


// tsconfig.json
{
  "compilerOptions": {
    //...
    "noImplicitAny": false,
   }
}

also answer
.ts file to introduce js library
(1) you can use [require] for example to introduce moment:const moment = require ('moment') in the file;
(2) directly install its ts library such as npm I @ types/moment

.
Menu