请问npm install weixin-js-sdk 无法在vue中import?
发布于 4 年前 作者 chao71 6408 次浏览 来自 问答

报错如下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 回复

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

回到顶部