infinitered / ignite-bowser

Bowser is now re-integrated into Ignite CLI! Head to https://github.com/infinitered/ignite to check it out.
https://infinite.red/ignite
MIT License
615 stars 140 forks source link

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

Open silencer07 opened 4 years ago

silencer07 commented 4 years ago

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) })


4. 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 commented 4 years ago

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 commented 4 years ago

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

ekzotech commented 3 years ago

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