fix: imports (part 2/2) (#13520)

Completes https://github.com/payloadcms/payload/pull/13513

That PR fixed it for the `admin` suite, but I had also encountered the
same issue in `live-preview`.

When searching for instances, I found others with the same pattern
within packages, which I took the opportunity to fix in case the same
error occurs in the future.
This commit is contained in:
German Jablonski
2025-08-20 13:08:55 +01:00
committed by GitHub
parent adb83b1e06
commit cf427e5519
27 changed files with 32 additions and 40 deletions

View File

@@ -2,8 +2,7 @@ import ObjectIdImport from 'bson-objectid'
import type { TextField } from '../config/types.js' import type { TextField } from '../config/types.js'
const ObjectId = (ObjectIdImport.default || const ObjectId = 'default' in ObjectIdImport ? ObjectIdImport.default : ObjectIdImport
ObjectIdImport) as unknown as typeof ObjectIdImport.default
export const baseIDField: TextField = { export const baseIDField: TextField = {
name: 'id', name: 'id',

View File

@@ -1,8 +1,7 @@
import Ajv from 'ajv' import Ajv from 'ajv'
import ObjectIdImport from 'bson-objectid' import ObjectIdImport from 'bson-objectid'
const ObjectId = (ObjectIdImport.default || const ObjectId = 'default' in ObjectIdImport ? ObjectIdImport.default : ObjectIdImport
ObjectIdImport) as unknown as typeof ObjectIdImport.default
import type { TFunction } from '@payloadcms/translations' import type { TFunction } from '@payloadcms/translations'
import type { JSONSchema4 } from 'json-schema' import type { JSONSchema4 } from 'json-schema'

View File

@@ -9,8 +9,7 @@ import { getCurrentDate } from '../utilities/getCurrentDate.js'
import { calculateBackoffWaitUntil } from './calculateBackoffWaitUntil.js' import { calculateBackoffWaitUntil } from './calculateBackoffWaitUntil.js'
import { getWorkflowRetryBehavior } from './getWorkflowRetryBehavior.js' import { getWorkflowRetryBehavior } from './getWorkflowRetryBehavior.js'
const ObjectId = (ObjectIdImport.default || const ObjectId = 'default' in ObjectIdImport ? ObjectIdImport.default : ObjectIdImport
ObjectIdImport) as unknown as typeof ObjectIdImport.default
export async function handleTaskError({ export async function handleTaskError({
error, error,

View File

@@ -23,8 +23,7 @@ import { TaskError } from '../../../errors/index.js'
import { getCurrentDate } from '../../../utilities/getCurrentDate.js' import { getCurrentDate } from '../../../utilities/getCurrentDate.js'
import { getTaskHandlerFromConfig } from './importHandlerPath.js' import { getTaskHandlerFromConfig } from './importHandlerPath.js'
const ObjectId = (ObjectIdImport.default || const ObjectId = 'default' in ObjectIdImport ? ObjectIdImport.default : ObjectIdImport
ObjectIdImport) as unknown as typeof ObjectIdImport.default
export type TaskParent = { export type TaskParent = {
taskID: string taskID: string

View File

@@ -1,7 +1,6 @@
import ObjectIdImport from 'bson-objectid' import ObjectIdImport from 'bson-objectid'
const ObjectId = (ObjectIdImport.default || const ObjectId = 'default' in ObjectIdImport ? ObjectIdImport.default : ObjectIdImport
ObjectIdImport) as unknown as typeof ObjectIdImport.default
export const isValidID = ( export const isValidID = (
value: number | string, value: number | string,

View File

@@ -8,7 +8,7 @@ import { useTheme } from '../../providers/Theme/index.js'
import { ShimmerEffect } from '../ShimmerEffect/index.js' import { ShimmerEffect } from '../ShimmerEffect/index.js'
import './index.scss' import './index.scss'
const Editor = (EditorImport.default || EditorImport) as unknown as typeof EditorImport.default const Editor = 'default' in EditorImport ? EditorImport.default : EditorImport
const baseClass = 'code-editor' const baseClass = 'code-editor'

View File

@@ -3,8 +3,10 @@ import type { DatePickerProps } from 'react-datepicker'
import React from 'react' import React from 'react'
import ReactDatePickerDefaultImport, { registerLocale, setDefaultLocale } from 'react-datepicker' import ReactDatePickerDefaultImport, { registerLocale, setDefaultLocale } from 'react-datepicker'
const ReactDatePicker = (ReactDatePickerDefaultImport.default || const ReactDatePicker =
ReactDatePickerDefaultImport) as unknown as typeof ReactDatePickerDefaultImport.default 'default' in ReactDatePickerDefaultImport
? ReactDatePickerDefaultImport.default
: ReactDatePickerDefaultImport
import type { Props } from './types.js' import type { Props } from './types.js'

View File

@@ -6,8 +6,7 @@ import React from 'react'
import { useRouteTransition } from '../../providers/RouteTransition/index.js' import { useRouteTransition } from '../../providers/RouteTransition/index.js'
import { formatUrl } from './formatUrl.js' import { formatUrl } from './formatUrl.js'
const NextLink = (NextLinkImport.default || const NextLink = 'default' in NextLinkImport ? NextLinkImport.default : NextLinkImport
NextLinkImport) as unknown as typeof NextLinkImport.default
// Copied from https://github.com/vercel/next.js/blob/canary/packages/next/src/client/link.tsx#L180-L191 // Copied from https://github.com/vercel/next.js/blob/canary/packages/next/src/client/link.tsx#L180-L191
function isModifiedEvent(event: React.MouseEvent): boolean { function isModifiedEvent(event: React.MouseEvent): boolean {

View File

@@ -24,8 +24,7 @@ import { FieldError } from '../FieldError/index.js'
import { FieldLabel } from '../FieldLabel/index.js' import { FieldLabel } from '../FieldLabel/index.js'
import { fieldBaseClass } from '../index.js' import { fieldBaseClass } from '../index.js'
const ObjectId = (ObjectIdImport.default || const ObjectId = 'default' in ObjectIdImport ? ObjectIdImport.default : ObjectIdImport
ObjectIdImport) as unknown as typeof ObjectIdImport.default
/** /**
* Recursively builds the default data for joined collection * Recursively builds the default data for joined collection

View File

@@ -10,8 +10,7 @@ import type { FieldAction } from './types.js'
import { mergeServerFormState } from './mergeServerFormState.js' import { mergeServerFormState } from './mergeServerFormState.js'
import { flattenRows, separateRows } from './rows.js' import { flattenRows, separateRows } from './rows.js'
const ObjectId = (ObjectIdImport.default || const ObjectId = 'default' in ObjectIdImport ? ObjectIdImport.default : ObjectIdImport
ObjectIdImport) as unknown as typeof ObjectIdImport.default
/** /**
* Reducer which modifies the form field state (all the current data of the fields in the form). When called using dispatch, it will return a new state object. * Reducer which modifies the form field state (all the current data of the fields in the form). When called using dispatch, it will return a new state object.

View File

@@ -37,8 +37,7 @@ import { resolveFilterOptions } from '../../utilities/resolveFilterOptions.js'
import { isRowCollapsed } from './isRowCollapsed.js' import { isRowCollapsed } from './isRowCollapsed.js'
import { iterateFields } from './iterateFields.js' import { iterateFields } from './iterateFields.js'
const ObjectId = (ObjectIdImport.default || const ObjectId = 'default' in ObjectIdImport ? ObjectIdImport.default : ObjectIdImport
ObjectIdImport) as unknown as typeof ObjectIdImport.default
export type AddFieldStatePromiseArgs = { export type AddFieldStatePromiseArgs = {
addErrorPathToParent: (fieldPath: string) => void addErrorPathToParent: (fieldPath: string) => void

View File

@@ -11,8 +11,7 @@ import {
} from 'payload' } from 'payload'
import { fieldAffectsData, fieldShouldBeLocalized, tabHasName } from 'payload/shared' import { fieldAffectsData, fieldShouldBeLocalized, tabHasName } from 'payload/shared'
const ObjectId = (ObjectIdImport.default || const ObjectId = 'default' in ObjectIdImport ? ObjectIdImport.default : ObjectIdImport
ObjectIdImport) as unknown as typeof ObjectIdImport.default
export type CopyDataFromLocaleArgs = { export type CopyDataFromLocaleArgs = {
collectionSlug?: CollectionSlug collectionSlug?: CollectionSlug

View File

@@ -2,7 +2,7 @@ import { createServer } from 'http'
import next from 'next' import next from 'next'
import { parse } from 'url' import { parse } from 'url'
const actualNext = next.default || next const actualNext = 'default' in next ? next.default : next
export const bootAdminPanel = async ({ port = 3000, appDir }) => { export const bootAdminPanel = async ({ port = 3000, appDir }) => {
const serverURL = `http://localhost:${port}` const serverURL = `http://localhost:${port}`
const app = actualNext({ const app = actualNext({

View File

@@ -7,7 +7,7 @@ import React from 'react'
import classes from './index.module.scss' import classes from './index.module.scss'
const Link = (LinkWithDefault.default || LinkWithDefault) as typeof LinkWithDefault.default const Link = 'default' in LinkWithDefault ? LinkWithDefault.default : LinkWithDefault
export type Props = { export type Props = {
appearance?: 'default' | 'none' | 'primary' | 'secondary' appearance?: 'default' | 'none' | 'primary' | 'secondary'

View File

@@ -6,7 +6,7 @@ import type { Post } from '../../../../payload-types.js'
import { Media } from '../Media/index.js' import { Media } from '../Media/index.js'
import classes from './index.module.scss' import classes from './index.module.scss'
const Link = (LinkWithDefault.default || LinkWithDefault) as typeof LinkWithDefault.default const Link = 'default' in LinkWithDefault ? LinkWithDefault.default : LinkWithDefault
export const Card: React.FC<{ export const Card: React.FC<{
alignItems?: 'center' alignItems?: 'center'

View File

@@ -6,7 +6,7 @@ import { Gutter } from '../Gutter/index.js'
import { CMSLink } from '../Link/index.js' import { CMSLink } from '../Link/index.js'
import classes from './index.module.scss' import classes from './index.module.scss'
const Link = (LinkWithDefault.default || LinkWithDefault) as typeof LinkWithDefault.default const Link = 'default' in LinkWithDefault ? LinkWithDefault.default : LinkWithDefault
export async function Footer() { export async function Footer() {
const footer = await getFooter() const footer = await getFooter()

View File

@@ -6,7 +6,7 @@ import { Gutter } from '../Gutter/index.js'
import classes from './index.module.scss' import classes from './index.module.scss'
import { HeaderNav } from './Nav/index.js' import { HeaderNav } from './Nav/index.js'
const Link = (LinkWithDefault.default || LinkWithDefault) as typeof LinkWithDefault.default const Link = 'default' in LinkWithDefault ? LinkWithDefault.default : LinkWithDefault
export async function Header() { export async function Header() {
const header = await getHeader() const header = await getHeader()

View File

@@ -6,7 +6,7 @@ import type { Props as ButtonProps } from '../Button/index.js'
import { Button } from '../Button/index.js' import { Button } from '../Button/index.js'
const NextLink = (NextLinkImport.default || NextLinkImport) as typeof NextLinkImport.default const NextLink = 'default' in NextLinkImport ? NextLinkImport.default : NextLinkImport
type CMSLinkType = { type CMSLinkType = {
appearance?: ButtonProps['appearance'] appearance?: ButtonProps['appearance']

View File

@@ -13,8 +13,8 @@ import classes from './index.module.scss'
const { breakpoints } = cssVariables const { breakpoints } = cssVariables
const NextImage = (NextImageWithDefault.default || const NextImage =
NextImageWithDefault) as typeof NextImageWithDefault.default 'default' in NextImageWithDefault ? NextImageWithDefault.default : NextImageWithDefault
export const Image: React.FC<MediaProps> = (props) => { export const Image: React.FC<MediaProps> = (props) => {
const { const {

View File

@@ -10,7 +10,7 @@ import RichText from '../../_components/RichText/index.js'
import { formatDateTime } from '../../_utilities/formatDateTime.js' import { formatDateTime } from '../../_utilities/formatDateTime.js'
import classes from './index.module.scss' import classes from './index.module.scss'
const Link = (LinkWithDefault.default || LinkWithDefault) as typeof LinkWithDefault.default const Link = 'default' in LinkWithDefault ? LinkWithDefault.default : LinkWithDefault
export const PostHero: React.FC<{ export const PostHero: React.FC<{
post: Post post: Post

View File

@@ -7,7 +7,7 @@ import React from 'react'
import classes from './index.module.scss' import classes from './index.module.scss'
const Link = (LinkWithDefault.default || LinkWithDefault) as typeof LinkWithDefault.default const Link = 'default' in LinkWithDefault ? LinkWithDefault.default : LinkWithDefault
export type Props = { export type Props = {
appearance?: 'default' | 'none' | 'primary' | 'secondary' appearance?: 'default' | 'none' | 'primary' | 'secondary'

View File

@@ -6,7 +6,7 @@ import type { Post } from '../../../../../payload-types.js'
import { Media } from '../Media/index.js' import { Media } from '../Media/index.js'
import classes from './index.module.scss' import classes from './index.module.scss'
const Link = (LinkWithDefault.default || LinkWithDefault) as typeof LinkWithDefault.default const Link = 'default' in LinkWithDefault ? LinkWithDefault.default : LinkWithDefault
export const Card: React.FC<{ export const Card: React.FC<{
alignItems?: 'center' alignItems?: 'center'

View File

@@ -6,7 +6,7 @@ import { Gutter } from '../Gutter/index.js'
import { CMSLink } from '../Link/index.js' import { CMSLink } from '../Link/index.js'
import classes from './index.module.scss' import classes from './index.module.scss'
const Link = (LinkWithDefault.default || LinkWithDefault) as typeof LinkWithDefault.default const Link = 'default' in LinkWithDefault ? LinkWithDefault.default : LinkWithDefault
export async function Footer() { export async function Footer() {
const footer = await getFooter() const footer = await getFooter()

View File

@@ -6,7 +6,7 @@ import { Gutter } from '../Gutter/index.js'
import classes from './index.module.scss' import classes from './index.module.scss'
import { HeaderNav } from './Nav/index.js' import { HeaderNav } from './Nav/index.js'
const Link = (LinkWithDefault.default || LinkWithDefault) as typeof LinkWithDefault.default const Link = 'default' in LinkWithDefault ? LinkWithDefault.default : LinkWithDefault
export async function Header() { export async function Header() {
const header = await getHeader() const header = await getHeader()

View File

@@ -6,7 +6,7 @@ import type { Props as ButtonProps } from '../Button/index.js'
import { Button } from '../Button/index.js' import { Button } from '../Button/index.js'
const NextLink = (NextLinkImport.default || NextLinkImport) as typeof NextLinkImport.default const NextLink = 'default' in NextLinkImport ? NextLinkImport.default : NextLinkImport
type CMSLinkType = { type CMSLinkType = {
appearance?: ButtonProps['appearance'] appearance?: ButtonProps['appearance']

View File

@@ -13,8 +13,8 @@ import classes from './index.module.scss'
const { breakpoints } = cssVariables const { breakpoints } = cssVariables
const NextImage = (NextImageWithDefault.default || const NextImage =
NextImageWithDefault) as typeof NextImageWithDefault.default 'default' in NextImageWithDefault ? NextImageWithDefault.default : NextImageWithDefault
export const Image: React.FC<MediaProps> = (props) => { export const Image: React.FC<MediaProps> = (props) => {
const { const {

View File

@@ -10,7 +10,7 @@ import RichText from '../../_components/RichText/index.js'
import { formatDateTime } from '../../_utilities/formatDateTime.js' import { formatDateTime } from '../../_utilities/formatDateTime.js'
import classes from './index.module.scss' import classes from './index.module.scss'
const Link = (LinkWithDefault.default || LinkWithDefault) as typeof LinkWithDefault.default const Link = 'default' in LinkWithDefault ? LinkWithDefault.default : LinkWithDefault
export const PostHero: React.FC<{ export const PostHero: React.FC<{
post: Post post: Post