Troubleshooting: Slice Simulator

Troubleshooting

In case you run into installation issues, here are some tips.

../.slicemachine/libraries-state.json does not exist
You need to run npm run slicemachine at least once before launching npm run dev.

Some dependencies are missing
Installation failed, try re-installing.

We can’t connect to the Simulator page

  • Make sure your project is running with npm run dev.
  • Check the value is correct in your sm.json, (eg. http://localhost instead of localhost).
  • This could be caused by accessing the wrong port.
  • Check the slice-simulator.jsx route
  • The slice-simulator.js filename is arbitrary, it can be anything you want for example _test.js or _components.js, as long as you specify it as shown in the next step.

Can’t find “localSliceSimulatorURL”
Update the sm.json file
In the sm.json add the property in the shape of http://localhost:PORT/PATH.
PORT = port on which the next.js project is running. PATH = path to the file created above.

:warning: Some versions of Webpack fails to resolve ESM modules correctly, to mitigate that, update the import to use CJS instead:

import { SliceSimulator } from "@prismicio/slice-simulator-vue/dist/index.cjs";

A post was split to a new topic: Slice Simulator Nuxt 3

Hello @Prismic-Support-Team,

Picking-up on the ../.slicemachine/libraries-state.json does not exist issue.

This error is persisting for me.

  • I have run npm run slicemachine before launching npm run dev / npm run buidl
  • I have rightfully pushed my each custom type and slice through slicemachine / localhost:9999
  • I can see all my slices correctly in slicemachine and on Prismic

Is there any reason for it not to work?

I am using next js 13 with the path set up of next js 12

PS : the libraries-state.json does not exist at all. I have tried re-doing in process from scratch, with a new repository and all, same error.
Screenshot 2022-12-26 at 6.15.54 PM

1 Like

This fix worked for me. Next.js - Module not found: Can't resolve '../.slicemachine/libraries-state.json' - #3 by nf_mastroianni

Hey @nonsoanetoh!

Thanks for the info. Indeed I have tried creating manually the file with a empty object it works too, although I don't think it is viable... Right?

A more permanent fix need to be done, right?

Hi, I think commenting here reopens this topic! I've been running into this error specifically when deploying to Vercel, as the "next build" command does not actually factor for initializing slicemachine before building the Next app.

Do you have any recommendations for initializing Slicemachine state on build from within the scripts folder, in such a way that Vercel can pick it up on one server?

Hello team, I can confirm the latest version of the Slice Machine V0.6.0, it can now run without a libraries-state.json file.

Adding to what @Pau said:
I just ran into this build error when upgrading from an old Slice Machine to the latest. I got the error

./pages/slice-simulator.jsx
Module not found: Can't resolve '../.slicemachine/libraries-state.json'
https://nextjs.org/docs/messages/module-not-found
> Build failed because of webpack errors

I had an outdated version of Slice Simulator that still imported state from a .json file.
Updating my code to the newer Slice Simulator code found here fixed it:

i am getting this error in slice machine:

crash-course-next@1.0.0 slicemachine
start-slicemachine

This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason:
Error: Error: Error in @slicemachine/adapter-next during custom-type-library:read hook: Unexpected string in JSON at position 1010
at StartSliceMachineProcess._validateProject (/home/olaide/work-space/Indige-v3/node_modules/start-slicemachine/dist/StartSliceMachineProcess.cjs:144:13)
at async StartSliceMachineProcess.run (/home/olaide/work-space/Indige-v3/node_modules/start-slicemachine/dist/StartSliceMachineProcess.cjs:61:5).

@prismic-admin can you please help with this? This happens when i try to spin up slice machine