Typescript: I can't read _**this.$store.state**_ when I run with `ts-node server/index.ts`

Created on 29 Aug 2019  路  12Comments  路  Source: nuxt/typescript

Describe the bug
I can't read _this.$store.state_ when I run with ts-node server/index.ts
but I can when I run with yarn nuxt-ts

I checked it inside _.nuxt_

This image with ts-node server/index.ts

image

this image with yarn nuxt-ts

image

Most helpful comment

@Him-2C Fixed it by adding that:

await nuxt.moduleContainer.ready()

just after https://github.com/Him-2C/nuxt-express-check-store/blob/master/server/index.ts#L11

This is something not documented in Programatically usage, but this need to be called so that modules are registered.

All 12 comments

@Him-2C From which file did you screenshot these images ?

.nuxt/store.js

I think you need further configuration for store when using Nuxt programatically but I don't have lot knowledge around that.
Do you have any repository with reproduction ? Is it a type error or the state is undefined ?

state is undefined

I will push CodeSandbox please wait me.

@Him-2C See :
https://github.com/nuxt/nuxt.js/blob/dev/packages/vue-app/template/store.js#L10
which leads to
https://github.com/nuxt/nuxt.js/blob/dev/packages/builder/src/builder.js#L399

I think you are missing saying in Nuxt config where the store dir is located.

@Him-2C I'm not sure CodeSandbox will work with Nuxt Programatically, it would be better you give a repository link then.

https://github.com/Him-2C/nuxt-express-check-store

please check yarn run:dev vs yarn dev

@Him-2C Fixed it by adding that:

await nuxt.moduleContainer.ready()

just after https://github.com/Him-2C/nuxt-express-check-store/blob/master/server/index.ts#L11

This is something not documented in Programatically usage, but this need to be called so that modules are registered.

Thank man is work!

So perfect like this.

image

I met this problem too,

i see await nuxt.ready() at release notes, but there is no description in programmatically.

Should it be documented? Or will it be changed in the feature.

Was this page helpful?
0 / 5 - 0 ratings