【发布时间】:2021-08-17 22:15:21
【问题描述】:
我不确定自己做错了什么,而且文档参差不齐,而且 Prismic 社区委员会的任何人都没有反应。我希望有人可以在这里帮助我:
我正在尝试将 slicezone 用于 nextjs,并且我正在关注文档,并且我正在为 slicezone '缺少加载程序'。
错误:
./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',
我的页面:
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
}
我应该注意,当我删除下一个切片区域并离开棱镜查询时,一切正常。我查看了我的配置文件,一切似乎都井井有条。
这是它为我自动安装的 sm-resolver.js(我认为这可能是罪魁祸首)。不知道去哪里:
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 '/'
}
}
我确定我做错了什么,因为文档非常模糊(尤其是必须与已设置的存储库集成),因此将不胜感激。 :)
【问题讨论】:
-
你试过用
next-transpile-modules转译next-slicezone吗? -
我什至不知道这是一件事,文档也没有说明它的需要
-
如果我没记错的话,SliceZone 是在配置 Prismic 内容以允许给定内容模型具有多个切片时。您似乎没有根据 API 调用
https://edit-elements.cdn.prismic.io/api/v2正确设置它 -
设置正确,因为切片正在通过。它正在添加下一个转译模块。我正在与 next-slicezone 的维护者讨论修复错误。我不确定我是否可以回答我自己的问题。
标签: reactjs next.js prismic.io