Closed
Description
What version of Next.js are you using?
latest
What version of Node.js are you using?
14.x
What browser are you using?
Chrome
What operating system are you using?
Linux
How are you deploying your application?
next dev / next start
Describe the Bug
I am consuming next/image
for an ESM library, but because it is only exported as CJS, it is not possible to resolve the default import correctly. For example:
import { jsx } from 'react/jsx-runtime.js';
import Image from 'next/image.js';
// fails: the Image() function exists at Image.default
jsx(Image, {});
// works: manually reference named CJS `default` member
jsx(Image.default, {});
Expected Behavior
It is not fun, but ideally Next would ship ESM entry-points, perhaps at next/package.mjs
, for consumption by third-party libraries or other ESM contexts (see microsoft/TypeScript#44501).
To Reproduce
See https://github.com/ctjlewis/default-resolution-bug.
$ node test.mjs
{ Image: { default: [Function: Image] } }
Warning: React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: object.
{
'$$typeof': Symbol(react.element),
type: { default: [Function: Image] },
key: null,
ref: null,
props: { src: 'https://via.placeholder.com/150' },
_owner: null,
_store: {}
}