Home > other >  Vite cannot resolve diff-match-patch in prod build
Vite cannot resolve diff-match-patch in prod build

Time:10-19

I am trying to switch from VueCLI to Vite. Everything works fine in dev mode in Vite however when I try to build prod I am getting this error.

[vite]: Rollup failed to resolve import "diff-match-patch" from "src/components/Viewer.vue?vue&type=script&setup=true&lang.ts".
This is most likely unintended because it can break your application at runtime.
If you do want to externalize this module explicitly add it to
`build.rollupOptions.external`
error during build:
Error: [vite]: Rollup failed to resolve import "diff-match-patch" from "src/components/DiffViewer.vue?vue&type=script&setup=true&lang.ts".
This is most likely unintended because it can break your application at runtime.
If you do want to externalize this module explicitly add it to

I cannot externalize this library since my application needs it. Here is how I am importing the library

<script setup lang="ts">
import { DIFF_DELETE, DIFF_EQUAL, DIFF_INSERT, diff_match_patch as DiffMatchPatch } from 'diff-match-patch'

This is working fine in VueCLI both in Dev and Prod build but not in Vite (prod mode) is there anyway to fix this problem.

CodePudding user response:

Checkout whether "diff-match-patch" is in package.json.

I tried with your code and get the same error when "diff-match-patch" are not installed.

  • Related