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 Rollup input extension .jsx

See original GitHub issue

Current Behavior

The file src/index.jsx is not recognized as a Rollup input:

https://github.com/palmerhq/tsdx/blob/943648edb06cd131f2c1751120cd1301804b480b/src/index.ts#L64-L69

Expected behavior

It should be possible to have the file src/index.jsx as the Rollup input.

Suggested solution(s)

async function jsOrTs(filename: string) {
  const extension = (await isFile(resolveApp(filename + '.ts')))
    ? '.ts'
    : (await isFile(resolveApp(filename + '.tsx')))
    ? '.tsx'
    : (await isFile(resolveApp(filename + '.jsx')))
    ? '.jsx'
    : '.js';

  return resolveApp(`${filename}${extension}`);
}

Your environment

Software Version(s)
TSDX 0.6.1
TypeScript 3.5.1
Browser Chromium
npm/Yarn npm
Operating System Ubuntu 18.04

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:6

github_iconTop GitHub Comments

2reactions
sispcommented, Jun 16, 2019

That’s true, but I was thinking to align tsdx’s features with CRA and CRA with --typescript set also resolves .js{x} files.

0reactions
agilgur5commented, Feb 1, 2020

Wanted to update folks on this issue as this was discussed in #443 as well and I’ve made a few related PRs to improve JSX support.

Per #443, TSDX actually already supports JSX, you just need to make sure your tsconfig.json has compilerOptions.allowJs set to true and that your include picks it up. TSDX does not by default allow JS or JSX but does support them when they are configured.

Isn’t the problem here that Typescript doesn’t support .jsx as a file extension for files containing jsx? As far as I know only .tsx is supported. More details: microsoft/TypeScript#30503

I’m not sure if this is the case or is still the case, but it works in TSDX. That might only be because TSDX runs Babel on top of rollup-plugin-typescript2, but I’m not really sure

There were some bugs related to JSX support, but those might not necessarily have caused issues for all JSX users. Related fixes:

  • #473 fixes an issue where custom Babel presets (like @babel/preset-react) weren’t always properly merged with TSDX defaults
  • #474 fixes the specific issue here in the OP, JSX extensions for entry files, with OP’s suggested solution
Read more comments on GitHub >

github_iconTop Results From Across the Web

Trying Rollup for React Applications | by Nathan Sebhastian
This tutorial will show you how to create a React-Rollup starter app from scratch and how Rollup compares against Webpack in terms of ......
Read more >
rollup-plugin-jsx - npm
rollup jsx plugin. This is a simple wrapper around jsx-transform. Make sure to go check that out for options. Install it with npm...
Read more >
Rollup + React not compiling JSX - Stack Overflow
All documentation/examples I've found using Rollup + React don't use the latest Babel so it might have something to do with Babel.
Read more >
rollup.js
A config file is an ES module that exports a default object with the desired options: export default { input: 'src/main.js', output: {...
Read more >
How to support subpath imports using React+Rollup+Typescript
In the early stages, packaging our React+Typescript library with Rollup was straight forward — feed Rollup with a single entry point as ...
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