question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

In Typescript, This dependency was not found

See original GitHub issue

我使用typescript语言开发Vue的应用,在加入此插件时出现了如下的错误,导致无法使用。 Error Info:

ERROR in /Users/wurining/Documents/WebStormPRO/ccw_personal/src/components/portal/PostList.vue
33:41 Could not find a declaration file for module 'vue-awesome-swiper'. '/Users/wurining/Documents/WebStormPRO/ccw_personal/node_modules/vue-awesome-swiper/dist/vue-awesome-swiper.js' implicitly has an 'any' type.
  Try `npm install @types/vue-awesome-swiper` if it exists or add a new declaration (.d.ts) file containing `declare module 'vue-awesome-swiper';`
    31 |
    32 |     import 'swiper/dist/css/swiper.css'
  > 33 |     import { swiper, swiperSlide } from 'vue-awesome-swiper'
       |                                         ^
    34 |
    35 |     @Component({
    36 |         swiper,
ERROR in /Users/wurining/Documents/WebStormPRO/ccw_personal/src/components/portal/PostList.vue
36:9 Argument of type '{ swiper: any; swiperSlide: any; }' is not assignable to parameter of type 'VueClass<Vue>'.
  Object literal may only specify known properties, and 'swiper' does not exist in type 'VueClass<Vue>'.
    34 |
    35 |     @Component({
  > 36 |         swiper,
       |         ^
    37 |         swiperSlide
    38 |     })
    39 |     export default class PostList extends Vue {
Version: typescript 2.9.2
Time: 645ms

使用vue-awesome-swiper的vue组件

<template>
    <div>
        <swiper :options="swiperOption">
            <swiper-slide>Slide 1</swiper-slide>
            <swiper-slide>Slide 2</swiper-slide>
            <swiper-slide>Slide 3</swiper-slide>
            <swiper-slide>Slide 4</swiper-slide>
            <swiper-slide>Slide 5</swiper-slide>
            <swiper-slide>Slide 6</swiper-slide>
            <swiper-slide>Slide 7</swiper-slide>
            <swiper-slide>Slide 8</swiper-slide>
            <swiper-slide>Slide 9</swiper-slide>
            <swiper-slide>Slide 10</swiper-slide>
            <div class="swiper-pagination" slot="pagination"></div>
        </swiper>
    </div>
</template>
<style lang="scss">
</style>
<script lang="ts">
    import Vue from "vue";
    import Component from "vue-class-component";

    import 'swiper/dist/css/swiper.css'
    import { swiper, swiperSlide } from 'vue-awesome-swiper'

    @Component({
        swiper,
        swiperSlide
    })
    export default class PostList extends Vue {
        swiperOption: object = {
            slidesPerView  : 3,
            slidesPerColumn: 2,
            spaceBetween   : 30,
            pagination     : {
                el       : ".swiper-pagination",
                clickable: true
            }
        };
    }
</script>

目前看来应该是没有添加typescript的d.ts声明文件。可否会写d.ts的老师添加一个pr?

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:1
  • Comments:12

github_iconTop GitHub Comments

11reactions
smac89commented, Dec 31, 2018

Create a file called vue-awesome-swiper.d.ts with the following:

declare module 'vue-awesome-swiper' {
    import Swiper, {SwiperOptions} from 'swiper';
    import Vue, {PluginObject} from 'vue';

    interface VueAwesomeSwiper extends PluginObject<SwiperOptions> {
        Swiper: Swiper;
        swiper: Vue;
        swiperSlide: Vue;
    }

    const VueAwesomeSwiper: VueAwesomeSwiper;
    export default VueAwesomeSwiper;

    export const swiper: Vue;
    export const swiperSlide: Vue;
    export { default as Swiper } from 'swiper';
}

Add devDependency for @types/swiper to get the rest of the type definitions

4reactions
chenjinxinlovecommented, Dec 17, 2018

添加

declare module 'vue-awesome-swiper' {
  export const swiper: any
  export const swiperSlide: any
}

declare module 'vue-lazyload'
Read more comments on GitHub >

github_iconTop Results From Across the Web

This dependency was not found - TypeScript, Vue
I am new to TS and Vue. Getting following error when trying to do vue-cli-service serve: This dependency was not found: * @store ......
Read more >
This dependency was not found when using typescript · Issue #4
I ran the command in example folder but I got an error. screenshot_5. However, The following tip does not work for me.
Read more >
How to set up TypeScript
TypeScript is available as a package on the npm registry available as "typescript" ... Then you use a dependency manager like npm, yarn...
Read more >
ts-node - npm
TypeScript execution and REPL for node.js, with source map and native ESM support. The latest documentation can also be found on our ...
Read more >
module-not-found - Next.js
The module you're trying to import is not installed in your dependencies ... When importing a module from npm this module has to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found