Skip to content
This repository has been archived by the owner on Jan 13, 2023. It is now read-only.

shorthand ".." import on mobx-state-tree model definition file is causing cryptic error #382

Open
silencer07 opened this issue Oct 10, 2020 · 3 comments

Comments

@silencer07
Copy link
Contributor

silencer07 commented Oct 10, 2020

Steps to reproduce:

  1. create an app using cli
  2. ignite generate model foo
  3. try to include using this syntax
import {FooModel} from ".."

export const RootStoreModel = types.model("RootStore").props({
  user: types.maybeNull(FooModel)
})
  1. see this error on log
    Error: [mobx-state-tree] expected mobx-state-tree type as argument 1, got undefined instead

How i fixed it:

  1. created index.ts file in foo folder inside models
  2. add this code export * from "./foo"
  3. change the import to

import {FooModel} from "../foo"

I wasted 2 hours of debugging and pulling my hair. only to realize this.

@silencer07
Copy link
Contributor Author

silencer07 commented Oct 10, 2020

solutions:

  1. we put the said index file and autoimport it in root-store during model generation
  2. remove the models/index.ts file
  3. I dont know if there is a babel config to automatically convert .. to "../foo/foo" during compilation? maybe this is better?

@carlosa54
Copy link

I had the same issue on my end when running yarn test. I ended up changing the '../' imports

@ekzotech
Copy link

Thank you for solution!
I wasted 5 hours trying to implement new store. Fixed with index.ts file.
So isn't it should be done when running "ignite generate model"? According to the link in the README when model is generated there should be also index.ts

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants