Skip to content

motion package breaks with "isValidProp is not a function" #165

Closed
@punkpeye

Description

@punkpeye

Describe the bug

I am trying to use http://npmjs.com/motion package.

It looks like they are doing something weird to import ESM module.

function loadExternalIsValidProp(isValidProp) {
	if (!isValidProp) return;
	shouldForward = (key) => key.startsWith("on") ? !isValidMotionProp(key) : isValidProp(key);
}
/**
* Emotion and Styled Components both allow users to pass through arbitrary props to their components
* to dynamically generate CSS. They both use the `@emotion/is-prop-valid` package to determine which
* of these should be passed to the underlying DOM node.
*
* However, when styling a Motion component `styled(motion.div)`, both packages pass through *all* props
* as it's seen as an arbitrary component rather than a DOM node. Motion only allows arbitrary props
* passed through the `custom` prop so it doesn't *need* the payload or computational overhead of
* `@emotion/is-prop-valid`, however to fix this problem we need to use it.
*
* By making it an optionalDependency we can offer this functionality only in the situations where it's
* actually required.
*/
try {
	/**
	* We attempt to import this package but require won't be defined in esm environments, in that case
	* isPropValid will have to be provided via `MotionContext`. In a 6.0.0 this should probably be removed
	* in favour of explicit injection.
	*/
	loadExternalIsValidProp((init_is_prop_valid_motion(), __toCommonJS(is_prop_valid_motion_exports)).default);
} catch {}

Here isValidProp is {} when it should be either undefined or function.

Reproduction

https://stackblitz.com/edit/vitejs-vite-9wqpscbo?file=index.html

Steps to reproduce

Just use motion

System Info

What's the point of this question if stackblitz is provided?

Used Package Manager

pnpm

Logs

entry.client-JHbadgic.js:3923 TypeError: isValidProp is not a function
    at shouldForward (proxy-DMFO4gzA.js:323:76)
    at filterProps (proxy-DMFO4gzA.js:357:7)
    at useRender (proxy-DMFO4gzA.js:1032:25)
    at MotionComponent (proxy-DMFO4gzA.js:600:15)
    at renderWithHooks (entry.client-JHbadgic.js:2515:21)
    at updateForwardRef (entry.client-JHbadgic.js:4034:15)
    at beginWork (entry.client-JHbadgic.js:4614:20)
    at performUnitOfWork (entry.client-JHbadgic.js:6412:14)
    at workLoopSync (entry.client-JHbadgic.js:6316:36)
    at renderRootSync (entry.client-JHbadgic.js:6300:5)

Validations

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions