Skip to content
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

jsx transform doesn't work #61

Closed
easylogic opened this issue Dec 10, 2022 · 19 comments · Fixed by #62
Closed

jsx transform doesn't work #61

easylogic opened this issue Dec 10, 2022 · 19 comments · Fixed by #62
Labels
bug Something isn't working
Milestone

Comments

@easylogic
Copy link

easylogic commented Dec 10, 2022

We are building with the latest version.

The jsx syntax in the tsx file is expressed as it is without being built.

Is there no way?

// index.mjs

  const buttonContent = <span>{children || ""}</span>;

The expected expression is:

const buttonContent = React.createElement("span", null, children || "");

Both cjs and mjs are the same.

jsx syntax doesn't compile.


// tsconfig 

{
    compilerOptions: {
        jsx: "react"  // not working 
        jsx: "react-jsx" // compile with jsx function 
    }

}
@cometkim
Copy link
Owner

this has fixed in rc.12

@cometkim
Copy link
Owner

if you set jsx mode as preserve or react, you have to have import statement import * as React from 'react' at the top

@easylogic
Copy link
Author

I will try it with rc.12.

@easylogic
Copy link
Author

easylogic commented Dec 10, 2022

rc.12 is not exists in npmjs.

how to install this version?

@cometkim
Copy link
Owner

cometkim commented Dec 10, 2022

rc 12 is exist in @rc channel
image

try

npm uninstall nanobundle
npm install -D nanobundle@rc

@easylogic
Copy link
Author

@cometkim

i installed rc.12

but It is still not working .

@cometkim
Copy link
Owner

Hmm let me take a look.

@cometkim
Copy link
Owner

I guess it is because of tree-shaking. Can you try again with actually exporting to your module tree?

@cometkim
Copy link
Owner

image
I see your Button component is compiling properly

@easylogic
Copy link
Author

it is old version compile.

@easylogic
Copy link
Author

I also found other error.
If you define "moduleResolution": "NodeNext", in tsconfig, the following error occurs.

TypeError: Cannot read properties of undefined (reading 'toLowerCase')
@react-elf/shared:build:     at result2tsconfig (file:///Users/user/github/test/react-elf/node_modules/tsconfck/dist/index.js:675:83)
@react-elf/shared:build:     at parseFile2 (file:///Users/user/github/test/react-elf/node_modules/tsconfck/dist/index.js:622:15)
@react-elf/shared:build:     at parseNative (file:///Users/user/github/test/react-elf/node_modules/tsconfck/dist/index.js:588:20)
@react-elf/shared:build:     at async it (file:///Users/user/github/test/react-elf/node_modules/nanobundle/bin.min.mjs:151:104)

@cometkim
Copy link
Owner

Yeah, it's caused by upstream 😅

I've already submitted PR to fix that dominikg/tsconfck#73

@cometkim
Copy link
Owner

cometkim commented Dec 10, 2022

it is old version compile.

So does it means you want to use the new jsxFactory (jsx()) from React 18?

@easylogic
Copy link
Author

I want it to be built in the form of React.createElement function.

Existing esbuild worked like that.

This worked similarly to vite, so I thought I could use it as it is.

@cometkim
Copy link
Owner

Ah my fault, compiles are belong to dist I see

@cometkim cometkim added the bug Something isn't working label Dec 10, 2022
@cometkim cometkim changed the title How to compile jsx syntax in .tsx file source? jsx preserve mode doesn't work Dec 10, 2022
cometkim added a commit that referenced this issue Dec 10, 2022
@cometkim
Copy link
Owner

I will publish it as rc.13 soon

@cometkim
Copy link
Owner

rc.13 is just published

@easylogic
Copy link
Author

good.

i will test it .

@easylogic
Copy link
Author

Oh it works fine.

The compilation result is good.

  const buttonContent = /* @__PURE__ */ React.createElement("span", null, children || "");

@cometkim cometkim changed the title jsx preserve mode doesn't work jsx transform doesn't work Dec 10, 2022
@cometkim cometkim added this to the v1 milestone Dec 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants