找不到模块“vue-xxx"的声明文件 [英] Could not find a declaration file for module 'vue-xxx'
问题描述
我尝试添加到我的项目中的任何 3rd 方 Vue.js 库都会引发以下错误:
Any 3rd party Vue.js library that I try to add to my project, throws the following error:
Could not find a declaration file for module 'vue-xxx'
我尝试过 'vue-treeselect'、'vue-select'、'vue-multiselect' 或多或少的结果相同(* 这些库不允许 import Modulename来自
,但需要const Modulename = require
).
I have tried 'vue-treeselect', 'vue-select', 'vue-multiselect' with more or less the same result (* those libraries don't allow import Modulename from
, but need const Modulename = require
).
我在 "dependencies": {
下添加那些在 package.json
.
I add those under "dependencies": {
in package.json
.
我正在使用 dotnet core 提供的 Vue.js SPA 模板.
I am using the SPA template for Vue.js provided by dotnet core.
带有 '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.
<小时>
package.json
package.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中生成了.
This error occured because of vue-xxxxxx
has been generated in JavaScript.
方法 1:为了避免这个问题,我只是用标准的 require() 替换它:
const vue-xxxxxx = require('vue-xxxxxx');
// import { vue-xxxxxx } from 'vue-xxxxxx'
方法 2:为了避免这个问题,我只是替换了 tsconfig.json
中的这些行"noImplicitAny": false,
"allowJs": true,
现在您可以使用 import 语句如下:
从'vue-xxxxxx'导入{ vue-xxxxxx}
Now you can use import statement as follows:
import { vue-xxxxxx } from 'vue-xxxxxx'
享受:)
这篇关于找不到模块“vue-xxx"的声明文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!