我尝试添加到项目中的任何第 3 方 Vue.js 库都会抛出以下错误:
Could not find a declaration file for module 'vue-xxx'
我已经尝试过“vue-treeselect”、“vue-select”、“vue-multiselect”,结果或多或少相同(*那些库不允许 import Modulename来自
,但需要 const Modulename = require
)。
我在 package.json
中的 "dependencies": {
下添加了这些内容。
我正在使用 dotnet core 提供的 Vue.js SPA 模板。
完整示例 'tree-select' :
import Treeselect from 'vue-treeselect';
/* ... */
value = null;
source = [
{
id: 'node-1',
label: 'Node 1',
children: [
{
id: 'node-1-a',
label: 'Node 1-A',
}
]
},
{
id: 'node-2',
label: 'Node 2',
}
];
/* ... */
<treeselect v-model="value"
:multiple="true"
:options="source" />
错误:
in [at-loader] ./ClientApp/components/mycomponent/mycomponent.ts:10:24
TS7016: Could not find a declaration file for module 'vue-treeselect'. 'path/to/project/node_modules/vue-treeselect/dist/vue-treeselect.js' implicitly has an 'any' type.
包.json
{
"name": "MyProject",
"private": true,
"version": "0.0.0",
"dependencies": {
"dygraphs": "^2.1.0",
"ol3-layerswitcher": "^1.1.2",
"vue-treeselect": "^1.0.6"
},
"devDependencies": {
"@types/dygraphs": "^1.1.6",
"@types/webpack-env": "^1.13.0",
"@types/vue": "^2.0.0",
"aspnet-webpack": "^2.0.1",
"awesome-typescript-loader": "^3.0.0",
"bootstrap": "^3.3.6",
"css-loader": "^0.25.0",
"event-source-polyfill": "^0.0.7",
"extract-text-webpack-plugin": "^2.0.0-rc",
"file-loader": "^0.9.0",
"isomorphic-fetch": "^2.2.1",
"jquery": "^3.1.1",
"style-loader": "^0.13.1",
"typescript": "^2.2.1",
"url-loader": "^0.5.7",
"vue": "^2.5.13",
"vue-loader": "^14.2.1",
"vue-property-decorator": "^6.0.0",
"vue-router": "^3.0.1",
"vue-template-compiler": "^2.5.13",
"webpack": "^2.2.0",
"webpack-hot-middleware": "^2.12.2"
}
}
最佳答案
这个错误是因为 vue-xxxxxx
已经在 JavaScript 中生成。
方法一: 为了避免这个问题,我只是用标准的 require() 替换它:
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'
享受 :) 😎
关于javascript - 找不到模块 'vue-xxx' 的声明文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49258849/