Skip to content

Next.js compiles .ts files outside of the application directory, but not .tsx files #19928

Closed
@goloroden

Description

@goloroden

Bug report

Describe the bug

Next.js supports TypeScript, which means that it is able to load .ts and .tsx files from within the application directory. In addition, Next.js also supports loading files from outside the application directory, e.g. to be able to use shared components. However, this only works for .ts files, not for .tsx files. This is unexpected and makes it hard to work with re-usable UI components, without having to come up with a separate npm module for them, which is often not what you need.

To Reproduce

We have set up a sample repository with a small, but complete example to reproduce the issue. Please see https://github.com/thenativeweb/temp--next-issue for details. The README.md file contains the detailed description on how to reproduce the issue.

Expected behavior

Next.js should not only support .ts files from outside the application directory, but .tsx files as well.

System information

  • OS: macOS Big Sur (11.0.1)
  • Version of Next.js: 10.0.3
  • Version of Node.js: 14.14.0
  • Deployment: npx next

Additional context

Setting up a separate npm module for the shared components is definitely not what we want to use. Even the various Next.js applications we have shall be in a single npm module, as they get started altogether using a custom server. So in the end, although our "real" repository contains multiple Next.js applications, there is only one actual application in the end. This is also the reason why we don't want to go down the next-transpile-modules road (it would force us to introduce separate modules as well).

Given that Next.js is able without any ado to handle .ts files from outside the application directory, we assume that the same should be possible for .tsx files.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions