JS引入import deviceInfo from '@ohos.deviceInfo'失败
如题,我创建了JSUI项目,在index.js中加入了import deviceInfo from '@ohos.deviceInfo',然后运行项目,运行失败,以下是错误信息:
Module name:com.ly.jstext01
Version:1.0.0
Pid:25354
Uid:11526
Reason:JS framework load js bundle failed
Lifetime: 0.000000s
Ability: com.ly.jstext01.MainAbility
page: pages/index/index.js
Js-Engine: v8
Stacktrace: ReferenceError: requireNapi is not defined
at requireModule (eval at Yr (<embedded>:5:265), <anonymous>:418:3)
at ./lib/script.js!./node_modules/babel-loader/lib/index.js?presets[]=E:\HarmonyOS sdk\js\2.2.0.3\build-tools\ace-loader\node_modules\@babel\preset-env&plugins[]=E:\HarmonyOS sdk\js\2.2.0.3\build-tools\ace-loader\node_modules\@babel\plugin-transform-modules-commonjs&comments=false!./lib/resource-reference-script.js!../../../../../HarmonyWorkspace/HarmonyWorkspace/jstext01/entry/src/main/js/default/pages/index/index.js.module.exports (eval at Yr (<embedded>:5:265), <anonymous>:275:36)
at eval (eval at Yr (<embedded>:5:265), <anonymous>:108:1)
at If (<embedded>:7:17075)
at a (<embedded>:4:30133)
at Object.../../../../../HarmonyWorkspace/HarmonyWorkspace/jstext01/entry/src/main/js/default/pages/index/index.hml?entry (eval at Yr (<embedded>:5:265), <anonymous>:106:1)
a
根据文档设备管理章节:https://developer.harmonyos.com/cn/docs/documentation/doc-references/js-apis-device-info-0000001169221192
从 API Version 6 开始支持。建议您先检查您的API版本信息,如果不是API Version 6,请更新到API Version 6。