-
Notifications
You must be signed in to change notification settings - Fork 19
using 'part:@sanity/form-builder' causes an error #59
Comments
I'm not sure why this would be occurring. The CLI includes the Line 33 in 8bb147a
Can you provide more details about your setup? Are you adding any babel options to the |
this is my config
I'm running npx sanity-codegen from within my sanity studio project directory |
it looks like this issue comes from using the sanity tabs plugin, we are using a private forked version of the plugin but I've tested it with the original plugin as well and I'm still getting the same error |
ahh i think this is because that plugin imports the form builder inside of its own code while also living in a potential option is to do let me play with this and see if I can get a scalable solution |
Can you try this config? import { SanityCodegenConfig } from 'sanity-codegen';
import { defaultBabelOptions } from 'sanity-codegen/cli';
const config: SanityCodegenConfig = {
schemaPath: './schemas/schema.js',
outputPath: './schema.ts',
babelOptions: {
...defaultBabelOptions,
plugins: [
...defaultBabelOptions.plugins.filter(
([key]) => key !== 'module-resolver'
),
[
'module-resolver',
{
root: ['.'],
alias: {
'part:@sanity/base/schema-creator':
'sanity-codegen/schema-creator-shim',
'all:part:@sanity/base/schema-type':
'sanity-codegen/schema-type-shim',
'part:@sanity/base/schema-type': 'sanity-codegen/schema-type-shim',
'^part:.*': 'sanity-codegen/no-op',
'^config:.*': 'sanity-codegen/no-op',
'^all:part:.*': 'sanity-codegen/no-op',
// 👇👇👇
'<forked-package-name>': 'sanity-codegen/no-op',
// 👆👆👆
},
},
],
],
},
};
export default config; replace |
thank you @ricokahler, It looks like this fixes the issue with the forked sanity-plugin-tabs but still getting the issue with the sanity seo plugin reported here #55 I'm using sanity codegen v0.8.2 |
I'm having the same issue, stemming from a custom input component. Here's the full file contents: import * as React from 'react';
import { nanoid } from 'nanoid';
import { withDocument } from 'part:@sanity/form-builder';
import { navigate } from '@sanity/default-layout/lib/datastores/urlState';
import { Card, Button } from '@sanity/ui';
import { useDocumentOperation } from '@sanity/react-hooks';
import { client } from '../../utils';
const { useState } = React;
export const AddNewChildArticleInputComponent: React.FC = withDocument(
({ document }) => {
if (!document._id) return null;
const { patch } = useDocumentOperation(
document._id.replace(/^drafts\./, ''),
document._type,
);
const [isLoading, setIsLoading] = useState(false);
const createDocument = (_type: string) => async () => {
// Create the new article
const newArticle = await client.create({
_type,
});
// Patch the parent's child articles with the new document
await patch.execute([
{ setIfMissing: { articles: { articles: [] } } },
{
insert: {
after: 'articles.articles[-1]',
items: [
{
_key: nanoid(),
_ref: newArticle._id,
_type: 'reference',
},
],
},
},
]);
const newUri = `/intent/edit/id=${newArticle._id}`;
// Navigate to edit the new document
navigate(newUri, { replace: false });
};
const buttonText = isLoading ? 'Creating...' : 'Create Child Article';
const buttonStyles = {
opacity: isLoading ? 0.6 : 1,
pointerEvents: isLoading ? 'none' : 'auto',
};
return (
<Card style={{ textAlign: 'center' }}>
<Button
mode="ghost"
text="Create Child Article"
onClick={createDocument('article')}
style={buttonStyles}
/>
<Button
mode="ghost"
text="Create Article Group"
onClick={createDocument('articleGroup')}
style={buttonStyles}
/>
</Card>
);
},
); I wasn't able to get it to work with custom babel settings, although the package name seems to have changed from when that solution was posted. I've tried:
But I may be attempting to import from the wrong location. Regardless, the codegen only fails when trying to parse that input component file - if I comment out the React component (and export a simple no-op component in its place), the codegen succeeds. Another option for this instance would be to strip out any custom |
@good-idea hey mate! i have the same problem, codegen failing cause of a custom component we added in the sanity desk. Could you solve your problem?
this is the component causing the error |
I bet it's because of the I do a silly thing: My directory is set up like:
My
Then, I have to bash scripts:
Finally, i call codegen with this command in my package.json:
(this also applies my prettier settings to the newly generated files but is unrelated) |
I also stumbled upon this problem when using custom input components. Also solved it by using a bash script to temporarily make dummy components. I simply added a DummyComponent.tsx to my components folder. DummyComponent.tsx
dummy-components.sh # !/usr/bin/env bash
mv ./src/components ./src/_components
mkdir ./src/components
find ./src/_components -type f -exec basename {} \; | xargs -I{} cp ./src/_components/DummyComponent.tsx "./src/components/{}" dummy-components-revert.sh # !/usr/bin/env bash
rm -rf ./src/components
mv ./src/_components ./src/components package.json "scripts": {
"start": "sanity start",
"build": "sanity build",
"build:types": "./dummy-components.sh && npx sanity-codegen schema-codegen && ./dummy-components-revert.sh"
}, |
Our app uses a bunch of imports from 'part:@sanity/form-builder' and 'part:@sanity/form-builder/path-event', We are also using a plugin that uses this import.
The cli outputs the following error when using this
The text was updated successfully, but these errors were encountered: