Vue FilePond Adapter
Vue FilePond is an official adapter component designed to integrate the powerful FilePond file upload library with Vue.js applications. Currently stable at version 7.0.4, this package provides a `FilePond` Vue component that wraps the underlying JavaScript library, enabling seamless file uploading experiences. While there isn't a strict release cadence, minor updates and bug fixes are released as needed. Its key differentiators include leveraging FilePond's robust feature set, such as drag-and-drop functionality, image optimization, accessibility features (keyboard navigation, AT software compatibility), responsive design, and support for various file types and upload methods (AJAX, base64, remote URLs). It's primarily designed for Vue 3, with a separate major version (v6) dedicated to Vue 2 support, ensuring broad compatibility while maintaining a modern API for newer Vue applications.
Common errors
-
Failed to resolve component: file-pond or [Vue warn]: Unknown custom element: <FilePond>
cause The FilePond component was not correctly registered with Vue, or the `vueFilePond` factory was not called to create the component.fixEnsure you import `vueFilePond`, call it with necessary plugins (e.g., `const FilePond = vueFilePond();`), and then register this `FilePond` constant in your component's `components` option. -
Cannot read properties of undefined (reading 'registerPlugin') or FilePond is not a constructor
cause FilePond plugins were passed directly as props to the `<FilePond>` component instead of being passed as arguments to the `vueFilePond` factory function, or the factory function itself wasn't called.fixPlugins should be passed as arguments to the `vueFilePond` function when creating the component: `const FilePond = vueFilePond(Plugin1, Plugin2);`. -
Module not found: Error: Can't resolve 'filepond/dist/filepond.min.css'
cause The `filepond` package or its styles are not installed or correctly resolved by your bundler.fixRun `npm install filepond` and ensure the import path `import "filepond/dist/filepond.min.css";` is correct and accessible within your project's module resolution configuration. -
[Vue warn]: Hydration completed but contains mismatches. (in SSR environments like Nuxt.js)
cause FilePond's client-side rendering conflicts with the server-side rendered HTML, leading to hydration errors.fixWrap the `<file-pond>` component in a `<no-ssr>` tag or use client-only rendering strategies specific to your SSR framework to ensure it's rendered only on the client side.
Warnings
- breaking Version 7.x+ of `vue-filepond` is exclusively compatible with Vue 3. Applications using Vue 2 must install `vue-filepond@^6.0.0`.
- gotcha FilePond plugins (e.g., image preview, file type validation) are not bundled with `vue-filepond` and must be installed, imported, and registered separately when creating the FilePond component.
- gotcha Core FilePond styles (`filepond.min.css`) and any plugin-specific styles must be explicitly imported into your project to ensure correct rendering.
- gotcha When using Server-Side Rendering (SSR) frameworks like Nuxt.js, the FilePond component should be wrapped in `<no-ssr>` tags or similar client-only hydration logic to prevent build issues or hydration mismatches.
- gotcha In older versions (`<=5.1.2`), there was a known issue where FilePond's detach mechanism would not run correctly, potentially leading to memory leaks. This was fixed in v5.1.3 and subsequent versions.
Install
-
npm install vue-filepond -
yarn add vue-filepond -
pnpm add vue-filepond
Imports
- vueFilePond
const vueFilePond = require("vue-filepond");import vueFilePond from "vue-filepond";
- FilePondPluginFileValidateType
const FilePondPluginFileValidateType = require("filepond-plugin-file-validate-type");import FilePondPluginFileValidateType from "filepond-plugin-file-validate-type";
- FilePond base styles
require("filepond/dist/filepond.min.css");import "filepond/dist/filepond.min.css";
- FilePond component
const FilePond = vueFilePond(FilePondPluginFileValidateType, FilePondPluginImagePreview);
Quickstart
<template>
<div id="app">
<file-pond
name="test"
ref="pond"
label-idle="Drop files here..."
v-bind:allow-multiple="true"
accepted-file-types="image/jpeg, image/png"
server="/api"
v-bind:files="myFiles"
v-on:init="handleFilePondInit"
/>
</div>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
import vueFilePond from "vue-filepond";
import "filepond/dist/filepond.min.css";
import "filepond-plugin-image-preview/dist/filepond-plugin-image-preview.min.css";
import FilePondPluginFileValidateType from "filepond-plugin-file-validate-type";
import FilePondPluginImagePreview from "filepond-plugin-image-preview";
const FilePond = vueFilePond(
FilePondPluginFileValidateType,
FilePondPluginImagePreview
);
export default defineComponent({
name: "app",
components: {
FilePond,
},
data() {
return { myFiles: ["cat.jpeg"] };
},
methods: {
handleFilePondInit() {
console.log("FilePond has initialized");
// FilePond instance methods are available on `this.$refs.pond`
},
},
});
</script>