HarmonyOS鸿蒙Next中ERROR: internal/modules/cjs/loader.js:888

发布于 1周前 作者 bupafengyu 来自 鸿蒙OS

HarmonyOS鸿蒙Next中ERROR: internal/modules/cjs/loader.js:888 安装三方库,DevEco Studio报错

操作步骤:

  1. DevEco Studio打开终端,输入 ohpm install @ohasasugar/hp-richtext
  2. 报错
Mon Sep 9 13:52:38 CST 2024
[13:52:40] [~/Desktop/MyApplication/entry/src/main/ets/pages] ❱❱❱ ohpm install @ohasasugar/hp-richtext
-e ERROR: internal/modules/cjs/loader.js:888
throw err;
^
Error: Cannot find module 'node:url'
Require stack:
- /Applications/DevEco-Studio.app/Contents/tools/ohpm/node_modules/glob/dist/commonjs/glob.js
- /Applications/DevEco-Studio.app/Contents/tools/ohpm/node_modules/glob/dist/commonjs/index.js
- /Applications/DevEco-Studio.app/Contents/tools/ohpm/lib/core/missing-dep-detect/DepStatementsMissingDetector.js
- /Applications/DevEco-Studio.app/Contents/tools/ohpm/lib/core/publish/PublishCore.js
- /Applications/DevEco-Studio.app/Contents/tools/ohpm/lib/commands/publish.js
- /Applications/DevEco-Studio.app/Contents/tools/ohpm/lib/index.js
- /Applications/DevEco-Studio.app/Contents/tools/ohpm/bin/pm-cli.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:885:15)
at Function.Module._load (internal/modules/cjs/loader.js:730:27)
at Module.require (internal/modules/cjs/loader.js:957:19)
at require (internal/modules/cjs/helpers.js:88:18)
at Object.<anonymous> (/Applications/DevEco-Studio.app/Contents/tools/ohpm/node_modules/glob/dist/commonjs/glob.js:5:20)
at Module._compile (internal/modules/cjs/loader.js:1068:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1097:10)
at Module.load (internal/modules/cjs/loader.js:933:32)
at Function.Module._load (internal/modules/cjs/loader.js:774:14)
at Module.require (internal/modules/cjs/loader.js:957:19) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/Applications/DevEco-Studio.app/Contents/tools/ohpm/node_modules/glob/dist/commonjs/glob.js',
'/Applications/DevEco-Studio.app/Contents/tools/ohpm/node_modules/glob/dist/commonjs/index.js',
'/Applications/DevEco-Studio.app/Contents/tools/ohpm/lib/core/missing-dep-detect/DepStatementsMissingDetector.js',
'/Applications/DevEco-Studio.app/Contents/tools/ohpm/lib/core/publish/PublishCore.js',
'/Applications/DevEco-Studio.app/Contents/tools/ohpm/lib/commands/publish.js',
'/Applications/DevEco-Studio.app/Contents/tools/ohpm/lib/index.js',
'/Applications/DevEco-Studio.app/Contents/tools/ohpm/bin/pm-cli.js'
]
}

更多关于HarmonyOS鸿蒙Next中ERROR: internal/modules/cjs/loader.js:888的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html

3 回复

这边测试下载该三方库没问题,重启电脑然后重新新建一个项目安装该三方库测试一下

更多关于HarmonyOS鸿蒙Next中ERROR: internal/modules/cjs/loader.js:888的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html


在HarmonyOS鸿蒙Next中,出现“ERROR: internal/modules/cjs/loader.js:888”错误通常与Node.js模块加载机制相关。此错误表明在加载某个模块时,内部模块加载器在路径解析或模块初始化过程中遇到问题。具体原因可能包括模块路径错误、模块文件缺失或模块依赖不兼容。

在鸿蒙Next中,Node.js作为开发环境的一部分,用于构建和运行JavaScript应用。若出现此错误,需检查以下内容:

  1. 确保模块路径正确,尤其在使用相对路径或绝对路径时。
  2. 确认模块文件存在,且文件名和扩展名无误。
  3. 检查模块依赖是否与当前Node.js版本兼容,必要时更新依赖或调整Node.js版本。
  4. 查看错误日志,定位具体问题模块和代码行,针对性修复。

此错误不直接涉及鸿蒙系统的核心功能,而是与Node.js模块加载机制相关。

在HarmonyOS鸿蒙Next中出现ERROR: internal/modules/cjs/loader.js:888错误,通常与Node.js模块加载问题相关。可能原因包括:

  1. 模块路径错误:确保模块路径正确,检查requireimport语句。
  2. 模块未安装:运行npm installyarn install安装缺失的依赖。
  3. Node.js版本不兼容:检查Node.js版本是否与项目要求匹配,必要时升级或降级。
  4. 缓存问题:尝试清除Node.js缓存,执行npm cache clean --force

确保开发环境配置正确,并检查相关配置文件。

回到顶部
AI 助手
你好,我是IT营的 AI 助手
您可以尝试点击下方的快捷入口开启体验!