New Project @slicemachine/init Issue

Describe your question/issue in detail

This is not a bug (I believe), so I am not recording a video. I want to create a new NextJS app but use an existing Prismic repository. I use create-next-app, cd into the directory and then:

@slicemachine/init@latest --repository nameofrepo

The custom types are imported beautifully. However, there's no slice information that comes over. I don't expect any of the slice JSX (.js, .jsx, .ts, .tsx) files to be populated, but I would hope/expect the mocks.json and models.json to come over.
As it stands now, when you run slicemachine after the init, all slices are set to be deleted on the next push from slicemachine.
This would result in some hefty data loss in all prismic documents.

Impacted feature

As explained above, reusing a prismic repository for a new NextJS project can result in a quick deletion of document content in the repository.

What steps have you taken to resolve this issue already?

I have tried this on two separate repositories to see if the behavior was limited to one. n=1 is not good. Not that n=2 is much better.

Errors

None

Your Role

Developer

Hosting provider

Vercel

Package.json file

{
  "name": "next-prismic-foundation",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "dev": "next dev --turbopack",
    "build": "next build",
    "start": "next start",
    "lint": "next lint",
    "slicemachine": "start-slicemachine"
  },
  "dependencies": {
    "@prismicio/client": "^7.17.2",
    "@prismicio/next": "^2.0.1",
    "@prismicio/react": "^3.2.1",
    "next": "15.3.0",
    "react": "^19.0.0",
    "react-dom": "^19.0.0"
  },
  "devDependencies": {
    "@eslint/eslintrc": "^3",
    "@slicemachine/adapter-next": "^0.3.74",
    "@tailwindcss/postcss": "^4",
    "@types/node": "^20",
    "@types/react": "^19",
    "@types/react-dom": "^19",
    "eslint": "^9",
    "eslint-config-next": "15.3.0",
    "slice-machine-ui": "^2.15.1",
    "tailwindcss": "^4",
    "typescript": "^5"
  }
}

Steps to reproduce

Explained in the first section.

does your repo have Legacy slices? That could cause a problem cause the model is a bit different.

It does not use legacy slices. However, the original project used the src folder, and I opted not to use it in the new project. Perhaps that’s the issue.
I also tried again and set the src folder to "yes" to see if it had anything to do with that question. It still did not bring over any slice information (mocks/models).

That may be the issue. When connecting the existing repo, all Types and Slices that exist in the repo also need to be present locally. If they’re not, Slice Machine will treat them as "new" or "missing" and could mark them for deletion.

To avoid that, we usually suggest either duplicating your original project folder as a base or manually copying over the slices and models.

Hi @Pau . I just want to clarify then, even though @slicemachine/init will pull the custom type structures from the Prismic respository, the init script will not pull the models/mocks for the slices? I ask because no matter what I do, the script does not pull any slice structure over. I suppose in reality, we just need the models. That information has to be in Prismic too, right?

I would presume that the structure of the slices is stored somewhere in Prismic (so it knows what fields to put in the builder etc), would it not also be possible to have init pull this info into mocks/models when running the init script?

I agree with you. We should definitely clarify this better in the documentation. Right now, Slice Machine can't pull the existing slice models directly from a previously created repository. So even though @slicemachine/init pulls the custom type structures, it won't fetch the slices' models or mocks.

We hope to improve Slice Machine in the future to fetch that data automatically, but in the meantime, here’s what I recommend:

Before running Slice Machine, use the Types API to fetch and save all the slices from your existing repo:

Thank you for this information. It will likely be marked the solution. In the meantime, I am looking to see what I can get from a repository that is using the legacy builder when I use the Types API. I see (from quite a while ago) there was/is an upgrade tool. However, I've also seen slicemachine/labs has something in there too. Can you offer advice on which is the way to go?

I am looking to test this tool out on a legacy repository that would be moved from Gatsby to Next: Upgrade Your Prismic Project with Our New Automated Tool Do I still have to sign up for early access? It's been quite some time since this was posted. Thank you @Pau for your help/insight.

1 Like

the upgrade tool should already be available by default in the latest versions of Slice Machine. Here’s a guide that walks you through how to enable it.

The guide recommends using environments to test changes before applying them broadly. However, if you're careful and follow the steps closely, you should be fine even if you’re not using environments.