Problem with "Pushing slices"

Hello. I'm experiencing issues with "Pushing slices" while initializing "npx @slicemachine/init@latest". I'm working with Next.js and have a customtypes folder where I store types with a folder structure like this, with an index.json and mocks.json in each folder. Today, I needed to add new slices, as I have multiple projects and a separate Prismic repository for each. So, I ran "npx @slicemachine/init@latest," but during initialization, I encountered the following error: "Error: Failed to read slice libraries: Error: Error in @slicemachine/adapter-next during slice-library:read hook: The following Slice models could not be read: [/Users/brooklyn-lab/projects/lotto-ui/apps/mcluck/customtypes/PageOptOutArbitration/model.json," but I don't have any "model.json" files. Has there been an update, and has the file structure changed? Recently, there were changes in the file structure, and all types and their mock data started being stored in a single "customtypes" directory. What could be causing this error?

I was able to work around this issue by copying my "index.json" file and renaming it to "model.json." However, this seems somewhat unusual as I now have two identical files with different names. Can someone please clarify what should be contained in "index.json" and "model.json"? It's essential to know the specific contents of these files for proper functionality.

Hi @ilya.stepaniuk ,

Welcome to the community!

This is a strange one, that I haven't seen before. I'm going to reach out to the team to try and get more information about this.

All the content of the customTypes folder were generated for you right? It wasn't something that you've been maintaining manually before this?

Thanks.

Hi Phil. The 'custometypes' folder used to populate when I created new types through Slicemachine or added/modified fields in these types. The content of the folder hasn't changed since the last global update when mock data was consolidated into a type description folder, and everything was working fine. My index file always looked like this:

Currently, I managed to resolve this issue by creating a 'model.json' file in each folder. Since leaving it empty wasn't an option, I put the type ID in it. Now it works fine, but it's unclear what changed and why SliceMachine wouldn't run without this file.

OK, I investigated this with the team and to help me understand what's going on. Can you show me the contents of your slicemachine.config.json file?

slicemachine.config.json

{
  "repositoryName": "brandName",
  "adapter": "@slicemachine/adapter-next",
  "libraries": ["./customtypes"],
  "localSliceSimulatorURL": "http://localhost:3000/slice-simulator"
}

OK, that's the issue here.

"libraries": ["./customtypes"],

Your Slice library should not be contained within the customtypes folder because SM tries to parse custom types as slices and since @slicemachine/adapter-next@0.3.11 , this generates an error. Before 0.3.11 , SM skipped them. Maybe that’s why you're encountering the issue now.

Move your Slices to a folder in the root of your project called Slices and update the slicemachine.config.json file.

If I create a slices folder and move all the files there, I get new problems. First of all, I can't delete the model file because the same error also occurs from the slices folder. When I moved all files to slices, when initializing slicemachine in slicemachine.config.json the path "libraries": ["./slices"] changes itself to "libraries": ["./src/slices"]. Although slices lies at the root of the project. And if you go to http://localhost:9999, all types are deleted



So you can't move all the folders to this file because you're also moving custom types. It should only be Slices that you are moving here. Do you which file are Slices and which are Custom Types?

If you're not sure what the difference between these are then you can move everything back to customtypes and set "libraries": [].

I have a model file that I had to create due to an error. I have a self-generated mocks.json file. But I am not sure under what conditions it is created, because it is not everywhere. I have a main file with a description of the type and keys - it is index.json and it must be in the customtypes folder, and next to it there must be mocks.json with any content. This solves my problem but doesn't look right)

OK, well, if it's working for now, that's fine.

However, for future reference and to be able to avoid errors I would follow the folder structure of this sample project and try not to manually edit the slices or customtypes folders, as Slice Machine will maintain these for you.

If you need anything else we're always here :slight_smile:

1 Like