uni-app 升级4.36后无法编译构建 提示 vite: Rollup failed to resolve import 问题
uni-app 升级4.36后无法编译构建 提示 vite: Rollup failed to resolve import 问题
类别 | 信息 |
---|---|
开发环境 | Windows |
操作系统版本 | 11 |
IDE | HBuilderX |
IDE版本 | 4.36 |
手机系统 | Android |
手机系统版本 | Android 15 |
手机厂商 | OPPO |
手机机型 | unkown |
页面类型 | vue |
Vue版本 | vue3 |
打包方式 | 云端 |
项目创建方式 | HBuilderX |
操作步骤:
npx degit dcloudio/uni-preset-vue#vite-ts my-vue3-project
cd my-vue3-project
npm init
npm add sentry-uniapp
在 main.ts
中增加如下代码
import { createSSRApp } from "vue";
import * as Sentry from 'sentry-uniapp'
import App from "./App.vue";
export function createApp() {
const app = createSSRApp(App);
console.log(Sentry)
return {
app,
};
}
启动编译
npx uni -p app
预期结果:
正确编译,代码及依赖被正确打包并编译
实际结果:
编译失败,提示以下错误
Please note that in running mode, due to log output, sourcemap, and uncompressed source code, the performance and package size are not as good as release mode.
Compiler version: 4.36(vue3)
Compiling...
[vite]: Rollup failed to resolve import "@sentry/types" from "/git/my-vue3-project/node_modules/sentry-uniapp/esm/index.js".
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`
bug描述:
IDE从 hbuildx 4.05 升级到 4.36 ,SDK 也使用 npx @dcloudio/uvm@latest 升级到最新,启动 app 构建时,提示以下错误
Please note that in running mode, due to log output, sourcemap, and uncompressed source code, the performance and package size are not as good as release mode.
Compiler version: 4.36(vue3)
Compiling...
[vite]: Rollup failed to resolve import "@sentry/types" from "/git/my-vue3-project/node_modules/sentry-uniapp/esm/index.js".
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`
发现使用官方工程同样出现该情况。
9 回复
看着是三方依赖的问题,这不提示有个 ts 的依赖没有安装吗?
你提到的官方工程是具体指哪个工程,有什么问题?
回复 DCloud_UNI_OttoJi: npx degit dcloudio/uni-preset-vue#vite-ts my-vue3-project
回复 d***@126.com: 就是无法识别第三方库的依赖
回复 d***@126.com: 举个例子,除了这个三方库,还有哪个依赖有问题
回复 DCloud_UNI_OttoJi: @turf/turf
截止发帖时间,最新4.36使用 pnpm 会有以上问题,需要使用 npm。
4.15以下则无该问题。
加一下 shamefully-hoist=true 试试,如果使用 npm 和 yarn 没问题,就用 yarn,依赖安装uniapp 不参与