sanity-plugin-prefixed-slug
sanity-plugin-prefixed-slug copied to clipboard
'import' and 'export' may appear only with 'sourceType: module' (1:1037)
Hi!
Trying to use this plugin for V3, but my whole studio crashed.
Module parse failed: 'import' and 'export' may appear only with 'sourceType: module' (1:1037) 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
var e;function r(e,r){ I thought this plugin was V3 compatible? Anyone knows how to fix this?
Node 16 and 18 tested.
Same problem here!
Plugin works great when running Sanity on its own. I'm only getting the above error when mounting studio on a next.js route. (similar to this sample project https://github.com/sanity-io/sanity-template-nextjs-clean)
Hope this helps.
@kylesalstrom
Yeah, I noticed the same, but mounting on a next.js route is the recommended way for Sanity v3 + Next.js. So this issue should be addressed :)
Anyone find a fix for this?
Same problem here. Looks like the plugin is not build/exported to support NextJS module loader.
Found a temporary solution. Looked in the source code and realised it is a custom component passed to the slug type, inside the schema. Got it to work my creating the components files myself, and imported them into the schema - that seems to work. I am also using [email protected].
Samle code.
// top of the schemafile
import { SlugInput } from "../../components/slug-prefix";
// further down
...
{
name: "slug",
title: "Slug",
type: "slug",
validation: (Rule: Rule) => Rule.required(),
components: {
input: SlugInput,
},
options: {
source: "title",
maxLength: 96,
urlPrefix: "/nyheder/",
storeFullUrl: true,
},
},
Further information that might help anyone else looking to do this:
- Find the plugin in your
node_modules
folder (it should be calledsanity-plugin-prefixed-slug
) - Copy the
src
folder from here - Paste it into your project, something like a
plugins
folder will do the trick - Rename
src
to something likesanity-plugin-prefixed-slug
- Import the
SlugInput
file you just created into the schema you want to use this component, like this:
import { SlugInput } from "plugins/sanity-plugin-prefixed-slug";
- The rest of the instructions are the same as the README