收藏
回答

请问npm install weixin-js-sdk 无法在vue中import?

报错如下Could not find a declaration file for module 'weixin-js-sdk'. 'e:/MyProject_20210610/JackWeb/node_modules/weixin-js-sdk/index.js' implicitly has an 'any' type.

Try `npm i --save-dev @types/weixin-js-sdk` if it exists or add a new declaration (.d.ts) file containing `declare module 'weixin-js-sdk';`ts(7016)

上面是报错信息。我的代码就是简单的一句:

import wx from "weixin-js-sdk"

我使用的版本如下:

  "dependencies": {

    "axios": "^0.21.1",

    "swiper": "^6.7.5",

    "vue": "^3.0.5",

    "vue-axios": "^3.2.4",

    "vue-router": "^4.0.10",

    "weixin-js-sdk": "^1.6.0"

  },

  "devDependencies": {

    "@vitejs/plugin-vue": "^1.2.5",

    "@vue/compiler-sfc": "^3.0.5",

    "node-sass": "^6.0.1",

    "sass": "^1.35.2",

    "sass-loader": "^12.1.0",

    "typescript": "^4.3.2",

    "vite": "^2.4.2",

    "vue-tsc": "^0.0.24"

  }

回答关注问题邀请回答
收藏

2 个回答

  • 仙
    2022-09-07

    有ts包了

    npm install weixin-js-sdk-ts


    导入

    import wx from "weixin-js-sdk-ts";


    2022-09-07
    有用
    回复
  • Jesse
    Jesse
    发表于小程序端
    2021-07-18

    那是ts报的错,说的是找不到类型声明文件,不影响代码正常运行的,你可以打印wx对象试试能否成功

    2021-07-18
    有用
    回复
登录 后发表内容