You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Vite构建前端项目时出现外部后端项目依赖解析错误的问题求助

Vite构建前端项目时出现外部后端项目依赖解析错误的问题求助

各位好,我碰到一个有点费解的问题,想请大家帮忙排查下:

我的项目文件夹结构是这样的:

APP
├─ 23-commerce-admin (前端Vue项目,用Vite构建)
└─ 23-commerce-api (后端Node项目)

单独运行前端项目23-commerce-admin是正常的,但执行构建命令时,突然抛出了这个错误:

✘ [ERROR] Could not resolve "pg-hstore"
../23-commerce-api/node_modules/sequelize/lib/dialects/postgres/hstore.js:2:23:
2 │ const hstore = require("pg-hstore")({ sanitize: true });

我的vite.config.js配置如下:

import { fileURLToPath, URL } from 'node:url';
import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';

// https://vitejs.dev/config/
export default defineConfig(() => {
  return {
    optimizeDeps: {
      include: ["quill"],
    },
    // build: {
    //   target: "esnext", // or "es2019",
    // },
    plugins: [vue()],
    resolve: {
      alias: {
        '@': fileURLToPath(new URL('./src', import.meta.url)),
      },
    },
  };
});

我实在搞不明白,为什么构建前端项目的时候,会去解析后端项目23-commerce-api里的Sequelize依赖?而且这两个项目单独运行都是完全正常的,有没有朋友能帮我分析下问题出在哪,以及怎么解决?

内容来源于stack exchange

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.08 14:29:30