Nextjs is doing hot module update when you change the code and you get error.
Problem is here https://github.com/aws-amplify/amplify-js/blob/master/packages/datastore/src/datastore/datastore.ts#L105
Maybe would be better to just return current schema. Also it's probably not the best design decision to execute code during import phase because of unexpected side effects.
+1
Subscribed, thank you @ericclemmons for your work on this, it's so frustrating when working in Next.
Here is a hack that worked for me:
instead of this:
import { Post } from "src/models"
Do this:
import { initSchema } from "@aws-amplify/datastore";
import { schema } from "src/models/schema";
let models;
if (typeof window !== "undefined") {
models = initSchema(schema);
}
// the Post model is now models.Post
This forces initSchema to run only client side.
This has been fixed as part of #6146. See this main thread for more info: https://github.com/aws-amplify/amplify-js/issues/5435#issuecomment-692990722
Most helpful comment
Here is a hack that worked for me:
instead of this:
Do this:
This forces initSchema to run only client side.