I'm receiving the error:
Module not found: Can't resolve '../.slicemachine/libraries-state.json'
when attempting to preview a slice in in the SliceSimulator with Nextjs. It's a brand new project and all dependencies are up-to-date. Running Node 18.
If I comment out the import and and the state prop, I can at least deploy the site without any errors.
My slice-simulator.js page:
import { SliceSimulator } from '@prismicio/slice-simulator-react'
import { SliceZone } from '@prismicio/react'
import { components } from '../slices'
import state from '../.slicemachine/libraries-state.json'
const SliceSimulatorPage = () => {
return (
<SliceSimulator
sliceZone={({ slices }) => (
<SliceZone slices={slices} components={components} />
)}
state={state}
/>
)
}
export default SliceSimulatorPage
@jgunderson Thank you for posting this. I tried to spin up a new Next+Prismic project, and followed the Prismic Docs for this. I received the same error when trying to preview a slice.
In v0.6 of slicemachine, I'm noticing that some things are off.
Docs state that npx @slicemachine/init was supposed to install @prismicio/next as well, but this did not happen for me
The .slicemachine/libraries-state.json file is not created
When I downgraded to 0.5.2, this file was created. I re-upgraded to .6. However, the changes I made to the slice are not reflected in the libraries-state.json file. The changes are saved within the slice's model.json file, though. This makes me wonder if something in the script that is supposed to copy the data from the model.json file to the libraries-state file isn't happening.
So @jgunderson based on the link I provided above, I was able to determine that a "fix" for now is to just create a libraries-state.json file in the exact location as specified in the import. Inside that file just place an empty object like this
// .slicemachine/libraries-state.json
{}
This should allow you to use the slicemachine as intended.
Thank you @nf_mastroianni. I can confirm that your temporary fix worked for me. I was also able to view slices in the Slice Simulator after adding this file.
Have you two noticed any downstream issues from this approach? I just discovered this thread after my Slicemachine state breaking a week ago. Your solution has been the only working resolution I've found
If you updated your packages in an existing project, you wouldn't see any issues (as the libraries-state file will already be there). However, if you spin up a new Next+Prismic project following Prismic Docs, you will run into the libraries-state.json file issue.
Hello team, we can confirm the latest version of Slice Simulator can now run without a libraries-state.json file.
this import should be removed, because the libraries state is not generated anymore by the slicemachine. import state from '../.slicemachine/libraries-state.json'
And chance its reference in the slice-simulator.js file from:
When I follow @Pau instructions, the slice simulator shows an empty white box. This renders the slice simulator to be useless. This solution does not work for me.
Additionally, I'm noting that when I save my click Save Mock Content, these values are not saved anywhere and are wiped out each time the page is manually refreshed or closed.
Some console errors when using the prosed deletion of the libraries-state.json file and state reference
Error: State does not validate expected format, see console logs for detailed report
at StateManager.load (index.js?60b4:276:1)
at async StateManager.reload (index.js?60b4:295:1)