<template>
<view class="title">{{title}}</view >
</template>
<script>
import qs from 'qs';
export default {
data() {
const stringify = qs.stringify({
a: [1, 2, 3]
}, {
arrayFormat: 'repeat',
})
console.log()
return {
title: stringify
}
},
onLoad() {
},
methods: {
}
}
</script>

- 发布:2025-06-25 09:49
- 更新:2025-07-02 19:42
- 阅读:161
【报Bug】Error: 'common/side-channel.js' is not defined, require args is 'side-channel' require依赖报错
产品分类: uniapp/App
PC开发环境操作系统: Windows
PC开发环境操作系统版本号: 11
HBuilderX类型: 正式
HBuilderX版本号: 4.45
手机系统: Android
手机系统版本号: Android 14
手机厂商: 小米
手机机型: Redmi K60
页面类型: vue
vue版本: vue3
打包方式: 离线
项目创建方式: HBuilderX
示例代码:
操作步骤:
正常版本:
"@dcloudio/vite-plugin-uni": "3.0.0-alpha-4010920240607001"
异常版本:
"@dcloudio/vite-plugin-uni": "3.0.0-alpha-4020120240617001"
正常版本:
"@dcloudio/vite-plugin-uni": "3.0.0-alpha-4010920240607001"
异常版本:
"@dcloudio/vite-plugin-uni": "3.0.0-alpha-4020120240617001"
预期结果:
预期正常启动
预期正常启动
实际结果:
真机报错:
18:08:23.992 [vite]: Rollup failed to resolve import "qs" from "C:/Users/yfmei/Documents/HBuilderProjects/test-pnpm-vite-require/pages/index/index.vue".
18:08:24.031 This is most likely unintended because it can break your application at runtime.
18:08:24.070 If you do want to externalize this module explicitly add it to
18:08:24.107 build.rollupOptions.external
启动白屏,报错:Error: module 'common/side-channel.js' is not defined, require args is 'side-channel'。
真机报错:
18:08:23.992 [vite]: Rollup failed to resolve import "qs" from "C:/Users/yfmei/Documents/HBuilderProjects/test-pnpm-vite-require/pages/index/index.vue".
18:08:24.031 This is most likely unintended because it can break your application at runtime.
18:08:24.070 If you do want to externalize this module explicitly add it to
18:08:24.107 build.rollupOptions.external
启动白屏,报错:Error: module 'common/side-channel.js' is not defined, require args is 'side-channel'。
bug描述:
vite-plugin-uni
h5 报错
X [ERROR] Could not resolve "side-channel"
node_modules/qs/lib/stringify.js:3:29:
3 │ var getSideChannel = require('side-channel');
╵ ~~~~~~~~~~~~~~
You can mark the path "side-channel" as external to exclude it from the bundle, which will remove
this error and leave the unresolved path in the bundle. You can also surround this "require" call
with a try/catch block to handle this failure at run-time instead of bundle-time.
真机报错
3.0.0-alpha-4010920240607001 之后的版本,从 3.0.0-alpha-4020120240617001 开始,无法使用含有 require 加载的第三方包。这里以 qs 举例,qs 依赖 side-channel:
18:31:12.634 "side-channel" is imported by "
18:31:12.664 No name was provided for external module "side-channel" in "output.globals" – guessing "require$$0".
18:31:18.090 应用【test-pnpm-vite-require】已启动
18:31:18.306 reportJSException >>>> exception function:createInstanceContext, exception:white screen cause create instanceContext failed,check js stack ->Uncaught ReferenceError: require$$0 is not defined
at (app-service.js:860:4)
测试后定位到问题来自 vite-plugin-uni,相关代码参考附件。希望可以通过开关或者命令行参数控制,而不是强制限制。
1***@163.com (作者)
demo 已上传,package.json 是有问题的依赖,package-correct.json 是正常版本
2025-07-02 18:37