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

产品配置器问题:无法使用/自定义ConfiguratorTextfieldService

解决Spartacus ConfiguratorTextfieldService导入报错问题

错误原因

你遇到的Module not found错误,是因为@spartacus/product-configurator包采用了ES模块的exports字段规范,只对外暴露官方指定的导入路径,你直接引用的内部路径./textfield/core/facade/configurator-textfield.service不在包的导出列表里,所以Node.js无法解析这个导入请求。

正确解决方案

1. 使用官方导出的入口路径导入

ConfiguratorTextfieldService属于textfield模块,需从@spartacus/product-configurator/textfield这个官方导出入口导入,而非直接引用内部文件路径:

import { ConfiguratorTextfieldService } from '@spartacus/product-configurator/textfield';

2. 保留构造函数注入代码

你的构造函数注入逻辑无需修改,保持原样即可:

constructor(
   private _configuratorTextfieldService: ConfiguratorTextfieldService
) {}

3. 验证包的导出配置(可选)

你可以打开/Users/.../node_modules/@spartacus/product-configurator/package.json,查看exports字段,确认其中包含类似以下的配置项,确保./textfield是合法的导出路径:

"exports": {
  "./textfield": "./textfield/index.js",
  // 其他导出项...
}

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.20 19:12:32