0

I have been using a new package.json entry points using exports. TypeScript works very well without any problems. So far, I have used it in a monorepo for a backend application where all files are .ts files. But now, I have a monorepo with frontend code where I need to make it work for .ts as well as .tsx files. This is how it is currently, which works fine for .ts files, but it cannot handle .tsx extension.

{
  "name": "@org/shared",
  "private": true,
  "exports": {
    "./*": {
      "node": {
        "development": "./*.ts",
        "default": "./dist/*.js"
      },
      "default": "./*.ts"
    }
  }
}

This is a shared package between backend and frontend in the monorepo. The tsx correctly picks up the development conditional export when I run it in watch mode for development. The problem happens when I encounter a .tsx file which is basically a React component. How do I make this configuration work so that it can pick up .tsx files if they exist, but otherwise, look for .ts files.

At the moment, this needs to work for Next.js, but ideally would love to see bundler-agnostic configuration.

2
  • @EstusFlask, As I said. I use tsx during development. The node's support for directly running typescript file is not to the level I need it to be. I have tsx files which I cannot import from as tsx runner tries to load ts file using development condition. I have many tsx files where I need to import code from in the backend. If this doesn't work, my only option is to do lots of refactoring and move the code from tsx to ts file. The requirement of Next.js is added only for providing slightly more context; that's all. Commented Sep 28 at 4:53
  • Have you tried "./*.tsx": { "node": { "development": "./*.tsx" } } or similar? You haven't provided a minimal reproducible example so I can't easily test your setup, but something like that is the first thing that comes to mind. Note also what the docs say: "During condition matching, earlier entries have higher priority and take precedence over later entries" (the order matters). Commented Oct 3 at 11:03

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.