Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

esm-node-services: exportDefault is not set for React #713

Closed
paralin opened this issue Sep 1, 2023 · 2 comments
Closed

esm-node-services: exportDefault is not set for React #713

paralin opened this issue Sep 1, 2023 · 2 comments

Comments

@paralin
Copy link

paralin commented Sep 1, 2023

@ije When I run parseCjsExports on "react" it returns exportDefault: false, when I would expect exportDefault: true. If we don't export "default" from React, when we run esbuild on the following code:

export * from "react";
import __cjs_exports$ from "react";
export const { Children, Component, Fragment, Profiler, PureComponent, StrictMode, Suspense, __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED, cloneElement, createContext, createElement, createFactory, createRef, forwardRef, isValidElement, lazy, memo, startTransition, unstable_act, useCallback, useContext, useDebugValue, useDeferredValue, useEffect, useId, useImperativeHandle, useInsertionEffect, useLayoutEffect, useMemo, useReducer, useRef, useState, useSyncExternalStore, useTransition, version } = __cjs_exports$;

... the generated code fails with "default" not being defined on the export.

However, if we add the following line (which would be done if exportDefault: true):

export { default } from 'react';

Everything seems OK.

Shouldn't the result of that script be exportDefault: true?

@ije
Copy link
Member

ije commented Sep 1, 2023

cjs always has the default export as esm, unless the __esModule exists

const React = require("react")
export default React
export { createElement, ... } = React 

@paralin
Copy link
Author

paralin commented Sep 1, 2023

@ije Ok, thanks. Where is that defined? I'm looking here but don't see it: https://github.com/esm-dev/esm.sh/blob/3324cc705a282b0bf7ae7ebcd15495fed838ace5/server/server_handler.go#L1286C1-L1286C25

@esm-dev esm-dev locked and limited conversation to collaborators Sep 4, 2023
@ije ije converted this issue into discussion #716 Sep 4, 2023

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants