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.
tsxduring development. The node's support for directly running typescript file is not to the level I need it to be. I havetsxfiles which I cannot import from astsxrunner tries to loadtsfile usingdevelopmentcondition. I have manytsxfiles 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 fromtsxtotsfile. The requirement ofNext.jsis added only for providing slightly more context; that's all."./*.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).