Spartacus中AsmSelectors调用getCustomerSupportAgentTokenState报错
解决Spartacus中
AsmSelectors.getCustomerSupportAgentTokenState不存在的TypeScript错误 问题代码
import { AsmSelectors } from '@spartacus/core';
this.customerSupportAgentTokenStateSubscription = this.store .select(AsmSelectors.getCustomerSupportAgentTokenState) .subscribe((data) => {//code here})
触发错误
Property 'getCustomerSupportAgentTokenState' does not exist on type 'typeof import("/storefront/node_modules/@spartacus/core/src/asm/store/selectors/asm-group.selectors")'.ts(2339)
可能原因及解决步骤
1. 版本适配问题
getCustomerSupportAgentTokenState这个选择器可能在你当前使用的Spartacus版本中尚未添加,或是在后续版本中被重命名/迁移了。
- 查看
package.json里@spartacus/core的版本号,对应版本的官方文档确认该选择器的存在状态。如果是旧版本,可考虑升级到包含该选择器的稳定版本;如果是新版本,检查是否有命名变更。
2. 导入路径错误
默认的AsmSelectors分组可能没有包含这个特定的选择器,尝试直接从具体路径导入:
// 替换原导入语句 import { getCustomerSupportAgentTokenState } from '@spartacus/core/src/asm/store/selectors/agent-token.selectors';
然后在代码中直接使用该选择器:
this.customerSupportAgentTokenStateSubscription = this.store .select(getCustomerSupportAgentTokenState) .subscribe((data) => {//code here})
3. ASM模块未正确配置
确保项目中已正确导入并配置ASM模块,否则相关状态和选择器不会被注册:
import { AsmModule } from '@spartacus/asm'; @NgModule({ imports: [ // ...其他模块 AsmModule ] }) export class AppModule {}
内容的提问来源于stack exchange,提问作者Miraj
相关产品推荐
相关产品推荐

