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

.tsx files not correctly parsed #163

Open
rmccue opened this issue Mar 7, 2021 · 3 comments
Open

.tsx files not correctly parsed #163

rmccue opened this issue Mar 7, 2021 · 3 comments
Milestone

Comments

@rmccue
Copy link
Member

rmccue commented Mar 7, 2021

The default ts-loader doesn't appear to work correctly, as it then never gets Babelified. Looks like it needs to be babel-loader!ts-loader instead of just ts-loader?

Digging further.

@rmccue
Copy link
Member Author

rmccue commented Mar 7, 2021

The following modifications look to be needed to properly support TS + JSX:

loaders.ts.defaults.loader = 'babel-loader';
module.exports = presets.development( {
	// ...
	resolve: {
		extensions: [
			'.ts',
			'.tsx',
			'.js',
			'.json',
		],
	},
] );

That is, the loader needs to be set to Babel (with @babel/preset-typescript added to the babelrc?) in order to parse the Babel parts from files (see this post). react-scripts does the same; they're also using ForkTsCheckerWebpackPlugin (matching this example); it's probably worth considering this, because ts-loader is hella slow at scale.

Also, the extensions need to include .ts/.tsx by default. Compare react-scripts' extension list (which is filtered based on TS support).

@kadamwhite
Copy link
Contributor

@rmccue Thanks for this catch. Could I ask you to put together a gist or a PR that demonstrates the issue? Should be able to get this fix in pretty quickly if so. Otherwise, it may need to wait for the next major as I should be able to allocate some more significant time once @igmoweb's Webpack 5 pr is ready to fly, and could tackle this during that.

@rmccue
Copy link
Member Author

rmccue commented Mar 11, 2021

Could potentially use https://github.com/rmccue/experimental-navigation/blob/main/.config/webpack.config.dev.js and toggle the additions off to see what it looks like; it's a fairly simple project.

Should be fairly easy to PR the change, will do so soon.

@kadamwhite kadamwhite added this to the 1.0 milestone Jun 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants