question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support React's new JSX transform

See original GitHub issue

Feature request

React 17 came with a new JSX transform feature which allow user to omit import React from 'react' from components. This feature has also been added back into v16, v15 and v0.14 then.

I moved from ts-loader to esbuild-loader for its performance. But when I want to use the new JSX transform I notice that esbuild has not supported yet while TypeScript 4.1 already supports it.

Why?

evanw suggested a plugin approach, and I believe this loader is a good place for doing it.

Alternatives

No response

Additional context

No response

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:8
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
alexandernstcommented, Aug 13, 2022

Nevermind, I found it. For anyone that might get here from google search, this is the config:

{
  test: /\.jsx?$/,
  exclude: /node_modules/,
  use: [
    {
      loader: "esbuild-loader",
      options: {
        loader: 'jsx',
        target: 'es2015',
        jsx: 'automatic',  // <--- this is the new option 
      }
    },
  ]
},

Using this new option renders this unnecessary:

plugins: [
  new webpack.ProvidePlugin({  // <-- can be removed
    React: 'react',            // <-- can be removed
  }),                          // <-- can be removed
],

@privatenumber Maybe this section of the docs should be updated in order to reflect this.

4reactions
privatenumbercommented, Aug 6, 2021

Evan means esbuild plugins, not just any plugin.

esbuild-loader uses esbuild’s transform API, which doesn’t support esbuild plugins.

If you want to omit the React import, you can use Webpack’s Provide Plugin.

Closing since this feature request belongs in esbuild rather than esbuild-loader.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Introducing the New JSX Transform – React Blog
Although React 17 doesn't contain new features, it will provide support for a new version of the JSX transform. In this post, we...
Read more >
React 17 introduces new JSX transform - Saeloun Blog
Now, with React adding support for a new version of JSX transform, React and, React-like libraries can optimize the creation of JSX elements ......
Read more >
React 17: New JSX Transform - JavaScript in Plain English
React 17, 16.4, 15.7, and 0.14.10 released a new feature that no longer requires importing React to transform JSX. This is a comprehensive...
Read more >
How to Use New JSX Transform IN REACT - Aspire Blogs
New JSX Transform in React blog presents what and why new JSX Transform use, JSX advantages, disadvantages and JSX hook examples.
Read more >
Enable the new JSX Transform in React Native 0.64
Enable the new JSX Transform in React Native 0.64 · import React. at the top of every file. · ReferenceError: Property 'React' doesn't...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found