HarmonyOS 动态import遇到错误:Failed to resolve the requested entryPoint. baseFileName

我在hap中通过 import { QuoteService } from ‘InterfaceLib’ 来调用的时候是正常的,但尝试上述动态导入时候,遇到了错误:

[ecmascript] Failed to resolve the requested entryPoint. baseFileName : .......

QuoteService.ets:

export class QuoteService implements QuoteInterface{
  serviceName: string = "QuoteService"
  constructor(serviceName: string) {
    this.serviceName = serviceName
  }
  description(): string {
    return this.serviceName + " description"
  }
  quoteMethod(): void {
    console.log('call quoteMethod')
  }
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.

InterfaceLib的Index.ets:

export { QuoteService } from './src/main/ets/InterfaceService/QuoteService'
export { QuoteInterface } from './src/main/ets/InterfaceService/QuoteInterface'
  • 1.
  • 2.

hap:

let inter = 'InterfaceLib'
import(inter).then((ns: ESObject) => {
  let quoteInstance: ESObject = new ns.QuoteService();
  console.log(quoteInstance.description())
})
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.

经过调试发现:

let inter = 'interfacelib’改成小写可以成功。

import使用以下两种方式都可以

import { QuoteService } from 'InterfaceLib'
import { QuoteInterface } from 'interfacelib'
  • 1.
  • 2.

为什么动态import的时候只有小写interfacelib可以?

HarmonyOS
2024-12-27 13:21:26
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
put_get

请检查oh-package.json5的dependencies里InterfaceLib的大小写 以及build-profile.json5里buildOption下packages里的InterfaceLib大小写。动态引入包名是需要区分大小写的,而 import { QuoteService } from 'InterfaceLib’的方式不用区分。

// oh-package.json5
"dependencies": {
  "InterfaceLib": "file:../InterfaceLib",
},
// build-profile.json5
"buildOption": {
  "arkOptions": {
    "runtimeOnly": {
      "sources": [
      ],
      "packages": [
      "InterfaceLib"
      ]
    },
  }
},
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
分享
微博
QQ
微信
回复
2024-12-27 16:44:56


相关问题
HarmonyOS 动态import失败
754浏览 • 1回复 待解决
HarmonyOS import动态导入库失败
621浏览 • 1回复 待解决
HarmonyOS 动态import so使用问题
693浏览 • 1回复 待解决
HarmonyOS import动态导入绝对路径
1263浏览 • 1回复 待解决
ArkTS import导入napi模块结果错误
3506浏览 • 0回复 待解决
动态import 变量表达式
1877浏览 • 1回复 待解决
HarmonyOS 动态import变量表达式做反射
661浏览 • 2回复 待解决
什么导入场景中适合使用动态import
1087浏览 • 1回复 待解决
动态设置文本导致致命错误
7714浏览 • 1回复 待解决