ixhyu
ixhyu
  • 发布:59 分钟前
  • 更新:58 分钟前
  • 阅读:14

uniapp-x写原生插件出现编译错误Note that you need plugins to import files that are not JavaScript

分类:鸿蒙Next

13:36:08.512 ⁠[plugin:uts] Expression expected (Note that you need plugins to import files that are not JavaScript)
13:36:08.512 at uni_modules/yjh-hw-login/native/src/main/ets/hw-account-kit.ets:15:0
13:36:08.512 15: interface HwiloginBuilderOptions extends NativeEmbedBuilderOptions {
13:36:08.512 ^
13:36:08.512 16: tagHint?: string
13:36:08.512 17: }⁠

59 分钟前 负责人:无 分享
已邀请:
Ask小助手

Ask小助手 - Ask社区AI助手

欢迎到专业群( uni-app x技术交流群 ) 咨询,群中有相关专业的管理员和群友。

根据你提供的编译错误信息,问题出现在鸿蒙原生插件开发中,ets 文件编译时报错 "Expression expected (Note that you need plugins to import files that are not JavaScript)"。

这个错误的核心原因是 ets 文件不能直接引用 uts 文件。在 uni-app x 的 UTS 原生混编开发中,如果你需要在 ets 文件中使用 uts 文件导出的对象或类型,需要通过一个 js 文件进行中转。

知识库中关于鸿蒙平台混编的注意事项明确说明了这一点:如果有 ets 引用 uts 内对象的需求,可以通过一个 js 文件进行中转。示例如下:

// deps.js  
export const utsExports = {}

本助手使用国产模型,生成代码准确率较低。强烈建议使用uni-agent生成代码

// index.uts  
import {  
  getAppVMMemoryInfo as getAppVMMemoryInfoOrigin  
} from './mem.ets'  
import { utsExports } from './deps.js'  

function hello() {  
  return 'hello from uts'  
}  
utsExports.hello = hello  

export function getAppVMMemoryInfo() {  
  return getAppVMMemoryInfoOrigin()  
}

本助手使用国产模型,生成代码准确率较低。强烈建议使用uni-agent生成代码

// mem.ets  
import { hidebug } from '@kit.PerformanceAnalysisKit';  
import { utsExports } from './deps.js'  

export function getAppVMMemoryInfo() {  
  console.log(utsExports.hello())  
  return hidebug.getAppVMMemoryInfo();  
}

本助手使用国产模型,生成代码准确率较低。强烈建议使用uni-agent生成代码

在你的 hw-account-kit.ets 文件中,可能尝试直接导入了 uts 相关的类型或接口,导致了编译失败。建议检查该文件中的 import 语句,确保 ets 文件没有直接引用 uts 文件,而是通过 js 文件作为桥梁来进行数据或方法的交互。

更详细的说明可以参考官方文档:UTS原生混编介绍 - harmonyos平台 - 注意事项

内容为 AI 生成,仅供参考

要回复问题请先登录注册