2***@qq.com
2***@qq.com
  • 发布:2025-09-15 16:16
  • 更新:2025-09-15 16:57
  • 阅读:24

自定义 uts 鸿蒙api插件 调用方法找不到包

分类:鸿蒙Next

//插件 uni_modules\wq-opharm\utssdk\app-harmony\index.uts
export function appone(){

console.info(` ----aaa `)  
}  

//uni_modules\wq-opharm\utssdk\interface.uts
export type appone =() =>void
//页面\pages\index.vue
<template>
<view class="content">
<button class="button" @click="openAppProductBtn">打开应用市场</button>
</view>
</template>

<script>
import { appone} from "@/uni_modules/wq-opharm"
export default {
data() {
return {

        }  
    },  
    onLoad() {  

    },  
    methods: {  
        openAppProductBtn() {  
            appone();  
        }  
    }  
}  

</script>
去掉函数 appone(); web正常运行
加上appone(); 报错
16:11:58.906 [vite] connecting...
16:11:58.906 [vite] connected.
16:11:58.982 [plugin:vite:import-analysis] Cannot find module 'D:/....../harm/uni_modules/wq-opharm' from 'D:/....../harm/pages/index/index.vue'
16:11:58.982 at pages/index/index.vue:1:0
16:11:59.102 App Launch at App.vue:4
16:11:59.102 App Show at App.vue:7
16:11:59.188 [Vue warn]: Unhandled error during execution of async component loader \n at <AsyncComponentWrapper>\nat <PageBody>\nat <Page>\nat <Anonymous>\nat <Layout>\nat <App>
16:11:59.231 ‍[⁠TypeError⁠]‍ {message: "Failed to fetch dynamically imported module: http://localhost:5173/pages/index/index.vue"}

2025-09-15 16:16 负责人:DCloud_UNI_OttoJi 分享
已邀请:
DCloud_UNI_OttoJi

DCloud_UNI_OttoJi - 日常回复 uni-app/x 问题,如果艾特我没看到,请主动私信

我使用你提供的工程,修改 <script lang='uts><script ,运行到鸿蒙功能正常,可以打印你的函数 log。

运行到 web 平台,你需要注释你的 appone 的引入、执行代码。运行无异常,你是不是没有针对 引入做条件编译?

<script >  
  // #ifdef APP-HARMONY  
    import { appone} from "@/uni_modules/wq-opharm"  
  // #endif  
    export default {  
        data() {  
            return {  

            }  
        },  
        onLoad() {  

        },  
        methods: {  
            openAppProductBtn() {  
        // #ifdef APP-HARMONY  
                appone();  
        // #endif  
            }  
        }  
    }  
</script>

要回复问题请先登录注册