We are planning on moving to a monorepo approach — Nx — for our marketing sites. Any time we want to start Slicemachine for a different site, we have to edit sm.json to change the apiEndpoint and libraries path.
Are there any solutions for this? For example: the ability to pass a flag to start-slicemachine to specify the path to sm.json.
Hello @jerry.nummi, thanks for reaching out. I'm not familiar with the monorepo environment but from what I can see online it's a strategy to structure your project that isn't fixed to one technology.
You should make sure that the command line is pointing to the correct location in your machine when you run the npm run slicemachine command. So if you wanna run site-1 your console should be in apps > site-1 and so on.
$ cd apps/site-1; start-slicemachine
`[slice-machine] An unexpected error occurred. Exiting...
Full error: Error: [api/env]: Unrecoverable error. Could not find package.json. Exiting..
Hey there, I asked around and our DevX team also recommends trating each app/site as its own Slice Machine installation. Here are examples of how to initiate the project with Yarn, pnpm, or npm 7/8.
You can target a specific app from the root level, like this:
This is the hack because Nx allows you to have one package.json at the root but the Slicemachine start script is expecting package.json to be in the same current working directory. (this script I believe)
I ran into an issue with this approach. While it works fine, when using Tailwind with NX, it processes all the files in the nested node_modules folder. This resulted in a 20-minute build time for my project. The problem lies in the way NX generates the content paths for Tailwind. To include all files, including those in your libs folder, the Tailwind config uses ...createGlobPatternsForDependencies(__dirname) . This generates a list of all content paths but adds the entire folder to be searched, including the nested node_modules folder in your app. To resolve this, I had to do the following:
const index = content.findIndex((item) => item.includes('apps/myapp'));
content[index] = content[index].replace('apps/myapp/', 'apps/myapp/(!node_modules)');
I am unable to determine what causing this issue. Either it is Clerk as I am getting request errors in ERR_TOO_MANY_REDIRECTS when the cms tries to request /slice-simulator or simple by removing the yarn.lock file from the app/myapp/ folder. When hosting on Netlify, you can only have one yarn.lock on the root.
The issue is with Clerk Authentication. When I remove the middleware, all is working fine. When Prismic is requesting the previews, Clerk middleware seems redirect first to the Clerk endpoint and then back to the /slice-simulator. This causes a too many redirects error on your side.
I have added the following to the config of the middlware:
'/(!slice-simulator)',
I am not sure this is working yet. Not completely tested. Also not quite sure this is right way. Here is my full middelware.ts.
const isProtectedRoute = createRouteMatcher(['/admin(.*)', '/courses(.*)']);
export default clerkMiddleware(
(auth, req) => {
const url = req.nextUrl.pathname;
// Skip Clerk processing for /slice-simulator and its sub-paths
if (url.startsWith('/slice-simulator')) {
return;
}
if (isProtectedRoute(req)) auth().protect();
},
{ debug: false },
);
export const config = {
matcher: [
// Skip Next.js internals and all static files, unless found in search params
'/((?!_next|[^?]*\\.(?:html?|css|js(?!on)|jpe?g|webp|png|gif|svg|ttf|woff2?|ico|csv|docx?|xlsx?|zip|webmanifest)).*)',
// Always run for API routes
'/(api|trpc)(.*)',
'/(!slice-simulator)',
],
};