I'm not sure what I'm doing wrong, and the documentation is pretty spotty and nobody on Prismic's Community board is very responsive. I'm hoping somebody can help me here:
I'm trying to use slicezone for nextjs, and I'm following along with the documentation and I'm 'missing a loader' for slicezone.
The error:
./node_modules/next-slicezone/index.js
Module parse failed: Unexpected token (6:2)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
|
| const PageInfo = ({ title, description }) => (
> <div
| style={{
| height: '80vh',
My page:
import { client } from '../../../prismic-configuration'
import Prismic from '@prismicio/client'
import { SliceZone } from 'next-slicezone'
import { useGetStaticProps, useGetStaticPaths} from 'next-slicezone/hooks'
import resolver from '../../../sm-resolver'
const CategoryProduct = ({slices}) => {
return(
<div>
</div>
)
}
export async function getStaticProps(props) {
const { params: { uid, category }} = props
console.log(uid, category)
const products = await client.query([
Prismic.Predicates.at('', 'product'),
])
const prods = {
props: {
products
}
}
return prods
}
export async function getStaticPaths() {
const results = {
paths: [
{
params: {
uid: 'handmade-film-transitions',
category: 'transitions'
}
}
], fallback: false
}
return results
}
I should note that when I remove next-slicezone and just leave the prismic query, everything works just fine. I've looked at my configuration files, and everything seems to be in order.
Here's the sm-resolver.js that it auto-installed for me (which I think may be the culprit). Not sure where to go:
module.exports = {
apiEndpoint: 'https://edit-elements.cdn.prismic.io/api/v2',
repoName: "edit-elements",
linkResolver: function(doc) {
if (doc.isBroken) {
return '/404';
}
if (doc.type === 'home') {
return '/';
}
if (doc.type === 'page') {
return '/page/' + doc.uid
}
if (doc.type === 'shop') {
return `/shop/${doc.uid}`
}
return '/'
}
}
I'm sure I'm doing something wrong because the docs are pretty nebulous (especially having to integrate with an already-setup repo), so any help would be greatly appreciated. :)
The issue was the version (as I and others) have set up doesn't work out of the box. You have to use next-transpile-modules (in its current state). sm-resolver is just for link-building (from Prismic support).
Here is the solution:
next.config.js:
package.json:
An example of a working dynamic page [category]/[uid]: