Skip to content

Lack of ESM entry-points prevents correct default import resolution #30402

Closed
@ctjlewis

Description

@ctjlewis

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: {}
}

Metadata

Metadata

Assignees

Labels

bugIssue was opened via the bug report template.please verify canaryPlease verify the issue with the latest canary branch.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions