You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

前端导入kuroshiro库遇模块解析及ERR_ABORTED错误求助

导入kuroshiro时模块解析失败及相关问题

导入kuroshiro到主JS文件时,出现错误:Failed to resolve module specifier "kuroshiro",提示相对引用必须以"/"、"./"或"../"开头。直接使用GitHub仓库中的示例代码无法运行,示例代码如下:

import Kuroshiro from "kuroshiro";
// Initialize kuroshiro with an instance of analyzer (You could check the [apidoc](#initanalyzer) for more information):
// For this example, you should npm install and import the kuromoji analyzer first
import KuromojiAnalyzer from "kuroshiro-analyzer-kuromoji";
// Instantiate
const kuroshiro = new Kuroshiro();
// Initialize
// Here uses async/await, you could also use Promise
await kuroshiro.init(new KuromojiAnalyzer());
// Convert what you want
const result = await kuroshiro.convert("感じ取れたら手");

尝试改用具体路径./jsfiles/kuroshiro后,出现ERR_ABORTED错误。已执行npm install kuroshiro和npm install kuroshiro-analyzer-kuromoji完成安装,并将node_modules中的dist文件夹复制到前端目录,按文档操作仍未解决问题。

另外,不清楚GitHub仓库中“build it from source with npm run build”的含义。

当前文件引入配置如下:
主JS文件引入:

<script type="module" src="http://localhost/wordpress/wp-content/themes/colorswebsite/script.js?ver=1.0.0"></script>

头部引入kuroshiro相关文件:

<script type="text/javascript" src="//localhost:3000/wordpress/wp-content/themes/colorswebsite/jsfiles/kuroshiro.min.js?ver=1.0.0" id="kuroshiro-min-js-js"></script>

<script type="text/javascript" src="//localhost:3000/wordpress/wp-content/themes/colorswebsite/jsfiles/kuroshiro-analyzer-kuromoji.min.js?ver=1.0.0" id="kuroshiro-js-js"></script>

内容的提问来源于stack exchange,提问作者Vinicius Chinen

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.24 17:37:02