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

Ubuntu服务器构建Vite React应用时Rollup导入解析失败求助

解决Vite React项目Ubuntu服务器构建时Rollup无法解析notistack的问题

问题描述

基于Vite开发的React应用在本地运行正常,但在Ubuntu服务器执行构建时出现以下Rollup错误:

Rollup failed to resolve import "notistack" from "/var/www/html/src/layouts/MainLayout.jsx".
[stderr]This is most likely unintended because it can break your application at runtime.

当前使用的Vite配置代码如下:

import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react-swc';
import * as path from 'path';

// https://vitejs.dev/config/
export default defineConfig({
  server: {
    port: 3000
  },
  plugins: [react()]
});

解决步骤

  • 先检查服务器依赖完整性:在项目根目录执行npm install或yarn install(对应你的包管理器),确保notistack被正确安装到node_modules中。本地已安装的依赖不会自动同步到服务器,必须在服务器上重新安装。
  • 确认package.json依赖项:打开项目根目录的package.json,检查dependencies里是否存在"notistack": "^x.x.x"(x.x.x为对应版本号)。如果没有,执行npm install notistack --save或yarn add notistack手动添加依赖。
  • 清理缓存后重试构建:执行npm run build -- --clearCache,或者直接删除node_modules、package-lock.json/yarn.lock文件,重新安装依赖后再执行构建命令。
  • 注:你的Vite配置未设置路径别名,所以基本可以排除别名配置导致的解析问题,核心问题大概率是依赖未正确安装。

内容的提问来源于stack exchange,提问作者Sanket Patil

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.31 17:20:31