我使用默认导出创建了 services/store.js,然后添加了“@service store;”在路线中。就在该行出现以下错误:
TypeError: Cannot read properties of undefined (reading 'default')
at Module.default (webpack://tkl/./services/store.js?:3:107)
at Resolver._extractDefaultExport (webpack://tkl/../rewritten-packages/ember-resolver.4afe6404/node_modules/ember-resolver/index.js?:389:25)
at Resolver.resolveOther (webpack://tkl/../rewritten-packages/ember-resolver.4afe6404/node_modules/ember-resolver/index.js?:150:32)
at Resolver.resolve (webpack://tkl/../rewritten-packages/ember-resolver.4afe6404/node_modules/ember-resolver/index.js?:171:23)
at resolve (/var/folders/1w/g50r82q15y31dhfvgqjznd300000gn/T/broccoli-7267293LUmMz80Ulj/out-752-packager_runner_embroider_webpack/assets/@ember/-internals/container/index.js:725:1)
at Registry.resolve (/var/folders/1w/g50r82q15y31dhfvgqjznd300000gn/T/broccoli-7267293LUmMz80Ulj/out-752-packager_runner_embroider_webpack/assets/@ember/-internals/container/index.js:506:1)
at Registry.resolve (/var/folders/1w/g50r82q15y31dhfvgqjznd300000gn/T/broccoli-7267293LUmMz80Ulj/out-752-packager_runner_embroider_webpack/assets/@ember/-internals/container/index.js:508:1)
at has (/var/folders/1w/g50r82q15y31dhfvgqjznd300000gn/T/broccoli-7267293LUmMz80Ulj/out-752-packager_runner_embroider_webpack/assets/@ember/-internals/container/index.js:738:1)
at Registry.has (/var/folders/1w/g50r82q15y31dhfvgqjznd300000gn/T/broccoli-7267293LUmMz80Ulj/out-752-packager_runner_embroider_webpack/assets/@ember/-internals/container/index.js:588:1)
at Registry.proto.validateInjections (/var/folders/1w/g50r82q15y31dhfvgqjznd300000gn/T/broccoli-7267293LUmMz80Ulj/out-752-packager_runner_embroider_webpack/assets/@ember/-internals/container/index.js:710:1)
at InternalFactoryManager.create (/var/folders/1w/g50r82q15y31dhfvgqjznd300000gn/T/broccoli-7267293LUmMz80Ulj/out-752-packager_runner_embroider_webpack/assets/@ember/-internals/container/index.js:369:1)
at Proxy.create (/var/folders/1w/g50r82q15y31dhfvgqjznd300000gn/T/broccoli-7267293LUmMz80Ulj/out-752-packager_runner_embroider_webpack/assets/@ember/-internals/container/index.js:204:1)
at instantiateFactory (/var/folders/1w/g50r82q15y31dhfvgqjznd300000gn/T/broccoli-7267293LUmMz80Ulj/out-752-packager_runner_embroider_webpack/assets/@ember/-internals/container/index.js:276:1)
at lookup (/var/folders/1w/g50r82q15y31dhfvgqjznd300000gn/T/broccoli-7267293LUmMz80Ulj/out-752-packager_runner_embroider_webpack/assets/@ember/-internals/container/index.js:223:1)
at Container.lookup (/var/folders/1w/g50r82q15y31dhfvgqjznd300000gn/T/broccoli-7267293LUmMz80Ulj/out-752-packager_runner_embroider_webpack/assets/@ember/-internals/container/index.js:121:1)
at ApplicationInstance.lookup (/var/folders/1w/g50r82q15y31dhfvgqjznd300000gn/T/broccoli-7267293LUmMz80Ulj/out-752-packager_runner_embroider_webpack/assets/@ember/-internals/runtime/lib/mixins/container_proxy.js:19:1)
at PrivateRouter.getRoute (/var/folders/1w/g50r82q15y31dhfvgqjznd300000gn/T/broccoli-7267293LUmMz80Ulj/out-752-packager_runner_embroider_webpack/assets/@ember/routing/router.js:183:1)
at UnresolvedRouteInfoByParam.fetchRoute (/var/folders/1w/g50r82q15y31dhfvgqjznd300000gn/T/broccoli-7267293LUmMz80Ulj/out-752-packager_runner_embroider_webpack/assets/router_js.js:714:1)
at UnresolvedRouteInfoByParam.get route [as route] (/var/folders/1w/g50r82q15y31dhfvgqjznd300000gn/T/broccoli-7267293LUmMz80Ulj/out-752-packager_runner_embroider_webpack/assets/router_js.js:648:1)
at URLTransitionIntent.applyToState (/var/folders/1w/g50r82q15y31dhfvgqjznd300000gn/T/broccoli-7267293LUmMz80Ulj/out-752-packager_runner_embroider_webpack/assets/router_js.js:1151:1)
at PrivateRouter.getTransitionByIntent (/var/folders/1w/g50r82q15y31dhfvgqjznd300000gn/T/broccoli-7267293LUmMz80Ulj/out-752-packager_runner_embroider_webpack/assets/router_js.js:1276:1)
at PrivateRouter.transitionByIntent (/var/folders/1w/g50r82q15y31dhfvgqjznd300000gn/T/broccoli-7267293LUmMz80Ulj/out-752-packager_runner_embroider_webpack/assets/router_js.js:1239:1)
at PrivateRouter.doTransition (/var/folders/1w/g50r82q15y31dhfvgqjznd300000gn/T/broccoli-7267293LUmMz80Ulj/out-752-packager_runner_embroider_webpack/assets/router_js.js:1357:1)
at PrivateRouter.handleURL (/var/folders/1w/g50r82q15y31dhfvgqjznd300000gn/T/broccoli-7267293LUmMz80Ulj/out-752-packager_runner_embroider_webpack/assets/router_js.js:1748:1)
at Router._doURLTransition (/var/folders/1w/g50r82q15y31dhfvgqjznd300000gn/T/broccoli-7267293LUmMz80Ulj/out-752-packager_runner_embroider_webpack/assets/@ember/routing/router.js:474:1)
at Router.handleURL (/var/folders/1w/g50r82q15y31dhfvgqjznd300000gn/T/broccoli-7267293LUmMz80Ulj/out-752-packager_runner_embroider_webpack/assets/@ember/routing/router.js:470:1)
at ApplicationInstance.visit (/var/folders/1w/g50r82q15y31dhfvgqjznd300000gn/T/broccoli-7267293LUmMz80Ulj/out-752-packager_runner_embroider_webpack/assets/@ember/application/instance.js:215:1)
at EmberApp._visit (/Users/boris/Projects/tkl/node_modules/fastboot/src/ember-app.js:269:20)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
at EmberApp.visit (/Users/boris/Projects/tkl/node_modules/fastboot/src/ember-app.js:329:7)
at FastBoot.visit (/Users/boris/Projects/tkl/node_modules/fastboot/src/index.js:86:18)
at /Users/boris/Projects/tkl/node_modules/fastboot-express-middleware/src/index.js:33:20
我尝试使用 getter 注入 store 或以某种方式调试/谷歌问题。然而,它没有任何结果。有人对此有什么想法吗?
这是生成错误的代码:
路线:
// app/routes/blogposts.ts
import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';
export default class BlogpostsRoute extends Route {
@service store;
// no matter what is inside this hook and whether it exists at all, no impact on the error
model(params) {
}
}
适配器:
// app/adapters/blogpost.ts
import RESTAdapter from '@ember-data/adapter/rest';
export default class BlogpostAdapter extends RESTAdapter {
host = 'http://localhost:3333';
}
declare module 'ember-data/types/registries/adapter' {
export default interface AdapterRegistry {
blogpost: BlogpostAdapter;
}
}
序列化器:
// app/serializers/blogpost.ts
import RESTSerializer from '@ember-data/serializer/rest';
export default class BlogpostSerializer extends RESTSerializer {}
declare module 'ember-data/types/registries/serializer' {
export default interface SerializerRegistry {
blogpost: BlogpostSerializer;
}
}
服务:
// app/services/service.js
export { default } from 'ember-data/store';
我明白了
// app/services/service.js
export { default } from 'ember-data/store';
尝试将此文件重命名为
// app/services/store.js
export { default } from 'ember-data/store';