乐趣区

关于typescript:解决Could-not-find-a-declaration-file-for-module-vuexxx问题

问题形容

ERROR in src/main.ts:6:21
TS7016: Could not find a declaration file for module 'vue-ls'. 'E:/123/node_modules/vue-ls/dist/vue-ls.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/vue-ls` if it exists or add a new declaration (.d.ts) file containing `declare module 'vue-ls';`
    4 | import Vue from 'vue'
    5 | import App from './App.vue'
  > 6 | import Storage from 'vue-ls'
      |                     ^^^^^^^^
    7 | import router from './router'
    8 | import store from './store/'

解决办法:

办法一:

为了防止这个问题,我只是用规范 require() 替换它

This error occured because of vue-xxxxxx has been generated in JavaScript.

const vue-xxxxxx = require('vue-xxxxxx');
// import {vue-xxxxxx} from 'vue-xxxxxx'

办法二:

为了防止这个问题,我只是在 tsconfig.json 中批改了这些行

"noImplicitAny": false,
"allowJs": true,

当初您能够应用 import 语句,如下所示

import {vue-xxxxxx} from 'vue-xxxxxx'
退出移动版