Comments (14)
Feels like we're so close to a solution here. Unfortunately, if I follow the above process, and use the Payload component inside of a collection field as an admin component, the page displays: "No matched field found for "MyFieldName".
Example
// export-reletionship-field.tsx
"use client"
import RelationshipField from "payload/dist/admin/components/forms/field-types/Relationship/index.js";
export { RelationshipField };
// my-field.ts
import { RelationshipField } from "./export-reletionship-field.tsx";
export const tenant: Field = {
name: "tenant",
type: "relationship",
relationTo: "tenants",
admin: {
position: "sidebar",
components: {
Field: RelationshipField,
},
},
If instead I used a non payload component, everything works fine:
...
components: {
Field: () => <div>Hello World</div>
} // Renders as expected on detail screen
...
It seems like this will be fixed automatically when payload exports all components as part of the bundle (payloadcms/payload#293), but its unclear when this will happen as it's been on the roadmap for quite a while.
from next-payload.
You are absolutely on the spot mate!
Freaking spent an entire day trying to figure that out.
And then adding transpilePackages: ["@payloadcms/plugin-seo"],
to next.config.js
- otherwise that is gonna break as well.
Cheers!
from next-payload.
@IAmNatch I'll agree with you that this is odd.. I did manage to get it to work - but the ways of doing so aren't logical 😵💫 Apparently I had to install the seo plugin, transpile it in next config and add the pages collection to the plugin. Then magically, your import of Payload fields is working as expected.. 😅
yarn add @payloadcms/plugin-seo
- Update next.config.js with following:
const nextConfig = {
transpilePackages: ["@payloadcms/plugin-seo"],
};
- Add to the payload config
import seo from "@payloadcms/plugin-seo";
...
plugins: [
seo({
collections: ["pages"],
}),
],
from next-payload.
I did some further research on the problems this morning, and it is quite clear it is Next.js that messes with it. Creating a clean Next.js with next-payload
installation with following versions:
"dependencies": {
"@payloadcms/next-payload": "^0.0.31",
"@radix-ui/react-slot": "^1.0.2",
"@types/node": "20.4.2",
"@types/react": "^18.2.15",
"@types/react-dom": "^18.2.7",
"eslint": "8.45.0",
"eslint-config-next": "13.4.10",
"next": "13.4.10",
"payload": "^1.11.2",
"react": "18.2.0",
"react-dom": "18.2.0",
"typescript": "5.1.6"
},
Then I installed the @payloadcms/plugin-seo
and added the plugin to a clean payload.config.ts
file:
plugins: [
seo({
collections: [],
}),
],
And it outputted the following errors:
- error /my-app/node_modules/payload/dist/admin/components/forms/Label/index.scss:1
@import '../../../scss/styles.scss';
^
SyntaxError: Invalid or unexpected token
at internalCompileFunction (node:internal/vm:73:18)
at wrapSafe (node:internal/modules/cjs/loader:1176:20)
at Module._compile (node:internal/modules/cjs/loader:1218:27)
at Module._extensions..js (node:internal/modules/cjs/loader:1308:10)
at Module.load (node:internal/modules/cjs/loader:1117:32)
at Module._load (node:internal/modules/cjs/loader:958:12)
at Module.require (node:internal/modules/cjs/loader:1141:19)
at require (node:internal/modules/cjs/helpers:110:18)
at Object.<anonymous> (/my-app/node_modules/payload/dist/admin/components/forms/Label/index.js:10:1)
at Module._compile (node:internal/modules/cjs/loader:1254:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1308:10)
at Module.load (node:internal/modules/cjs/loader:1117:32)
at Module._load (node:internal/modules/cjs/loader:958:12)
at Module.require (node:internal/modules/cjs/loader:1141:19)
at require (node:internal/modules/cjs/helpers:110:18)
at Object.<anonymous> (/my-app/node_modules/payload/dist/admin/components/forms/field-types/Text/Input.js:8:33)
at Module._compile (node:internal/modules/cjs/loader:1254:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1308:10)
at Module.load (node:internal/modules/cjs/loader:1117:32)
at Module._load (node:internal/modules/cjs/loader:958:12)
at Module.require (node:internal/modules/cjs/loader:1141:19)
at require (node:internal/modules/cjs/helpers:110:18)
at Object.<anonymous> (/my-app/node_modules/payload/dist/admin/components/forms/field-types/Text/index.js:33:33)
at Module._compile (node:internal/modules/cjs/loader:1254:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1308:10)
at Module.load (node:internal/modules/cjs/loader:1117:32)
at Module._load (node:internal/modules/cjs/loader:958:12)
at Module.require (node:internal/modules/cjs/loader:1141:19)
at require (node:internal/modules/cjs/helpers:110:18)
at Object.<anonymous> (/my-app/node_modules/payload/components/forms.js:27:16)
at Module._compile (node:internal/modules/cjs/loader:1254:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1308:10)
at Module.load (node:internal/modules/cjs/loader:1117:32)
at Module._load (node:internal/modules/cjs/loader:958:12)
at Module.require (node:internal/modules/cjs/loader:1141:19)
at require (node:internal/modules/cjs/helpers:110:18)
at Object.<anonymous> (/my-app/node_modules/@payloadcms/plugin-seo/dist/fields/MetaDescription.js:79:15)
at Module._compile (node:internal/modules/cjs/loader:1254:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1308:10)
at Module.load (node:internal/modules/cjs/loader:1117:32)
at Module._load (node:internal/modules/cjs/loader:958:12)
at Module.require (node:internal/modules/cjs/loader:1141:19)
at require (node:internal/modules/cjs/helpers:110:18)
at Object.<anonymous> (/my-app/node_modules/@payloadcms/plugin-seo/dist/index.js:23:25)
at Module._compile (node:internal/modules/cjs/loader:1254:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1308:10)
at Module.load (node:internal/modules/cjs/loader:1117:32)
at Module._load (node:internal/modules/cjs/loader:958:12)
at Module.require (node:internal/modules/cjs/loader:1141:19)
at require (node:internal/modules/cjs/helpers:110:18) {
digest: undefined
}
from next-payload.
So basically - If you are using Next.js version [email protected]
and DON'T use custom components that import resources from Payload - then it seems to be working fine. Also with SEO plugin.
from next-payload.
This might help you
#38 (comment)
from next-payload.
I still have this issue when importing payload's CodeField component when following the code described here (last comment).
This import is causing the problem:
import CodeField from "payload/dist/admin/components/forms/field-types/Code";
But the payload
package is already added in the transpilePackages
by the withPayload
function.
from next-payload.
@ToolReaz You'll likely have to add 'use client'
to the top of that file.
from next-payload.
@ToolReaz You'll likely have to add
'use client'
to the top of that file.
This is causing another error:
/home/toolreaz/dev/projects/myproject/node_modules/payload/dist/fields/config/sanitize.js:51
field.blocks = field.blocks.map((block) => ({ ...block, fields: block.fields.concat(baseBlockFields_1.baseBlockFields) }));
^
TypeError: Cannot read properties of undefined (reading 'concat')
at /home/toolreaz/dev/projects/myproject/node_modules/payload/dist/fields/config/sanitize.js:51:90
at Array.map (<anonymous>)
at /home/toolreaz/dev/projects/myproject/node_modules/payload/dist/fields/config/sanitize.js:51:41
at Array.map (<anonymous>)
at sanitizeFields (/home/toolreaz/dev/projects/myproject/node_modules/payload/dist/fields/config/sanitize.js:16:19)
at sanitizeCollection (/home/toolreaz/dev/projects/myproject/node_modules/payload/dist/collections/config/sanitize.js:126:47)
at /home/toolreaz/dev/projects/myproject/node_modules/payload/dist/config/sanitize.js:44:106
at Array.map (<anonymous>)
at sanitizeConfig (/home/toolreaz/dev/projects/myproject/node_modules/payload/dist/config/sanitize.js:44:63)
at buildConfig (/home/toolreaz/dev/projects/myproject/node_modules/payload/dist/config/build.js:19:42)
I'm using payload 1.13.4 and next-payload 0.0.35
from next-payload.
That is likely because your file is ending with .ts
instead of .tsx
.
from next-payload.
I just tried to follow your code example - and it seems to work. Not sure why you get an error saying No matched field found for "MyFieldName"
as none of these fields are named MyFieldName
recording.mp4
from next-payload.
Sorry, I was originally trying to generalize the field name, but in the example I ended up using the actual field. In my case, the error says : "No matched field found for Tenant".
I'll try and create a repro for you this evening.
from next-payload.
Here's minimal reproduction of the issue, using a page
relation instead of a tenant
relation for simplicity:
next-payload-repro--importing-from-dist.zip
And here's a video on my end:
https://github.com/payloadcms/next-payload/assets/15078788/a5145599-e7d3-4cd4-b477-9b41bcd46a12
Thanks for your interest in this issue!
from next-payload.
Weird! I tried this in the repro I shared earlier, but with no luck. I'm not seeing anything in the plugin-seo source code that would affect packaging like this (ie re-exporting of components, or webpack modifications), but perhaps I missed something. Let me know if you'd like another repro.
from next-payload.
Related Issues (20)
- Broken with Next.js 14 HOT 10
- Local File Upload Path Mismatch? HOT 4
- Warning: ToastContainer HOT 2
- getPayload is not a function / req.payload is a Promise? HOT 3
- Payload CMS overrides styled-component GlobalStyles HOT 1
- App crashes with postgresql HOT 2
- Unable to set up with postgres on 13.5.6 (works with mongodb) HOT 1
- Cannot find module '../payload/payload.config.ts'
- API Key: You are not allowed to perform this action. HOT 1
- `Error [ERR_REQUIRE_ESM]: require() of ES Module` error when using component in /pages instead of /app folder HOT 4
- Custom views don't work HOT 2
- `getPayloadClient()` fails in server actions HOT 2
- Builds dont work with next14 HOT 6
- Status 500 error with vercel deploy (next14) HOT 2
- Unexpected handler pages/api/[collection]/lib/worker.js HOT 1
- Can't login '/admin' after creating initial admin account on '/admin' page (Next.JS 14 with next-payload) HOT 4
- Incompatability with lexical editor HOT 1
- Unexpected handler pages/api/[collection]/lib/worker.js in next-payload HOT 5
- `loadConfig is not a function` when running `next-payload build` HOT 2
- Full restart required for changes to apply correctly HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from next-payload.