-
-
Notifications
You must be signed in to change notification settings - Fork 18
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
Question: avoid relative paths / file extensions #1
Comments
File extensions are definitely required if you're building for ESM. No way around that. Just put
For example, this builds just fine (fixed the // ./package.json
{}
// ./tsconfig.json
{
"compilerOptions": {
"baseUrl": "./src",
"declaration": true,
"declarationMap": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"inlineSources": true,
"jsx": "react",
"module": "nodenext",
"moduleResolution": "nodenext",
"noUncheckedIndexedAccess": true,
"resolveJsonModule": true,
"skipLibCheck": true,
"sourceMap": true,
"strict": true,
"target": "es2022"
}
}
// ./src/utils/fooBar.ts
export const fooBar = () => true;
// ./src/utils/index.ts
export * from 'utils/fooBar.js'
// ./src/handler.ts
import { fooBar } from 'utils/index.js';
fooBar(); But then when you try to run it:
Your options:
Option (4) is this:
But, that only works if the package is linked into a A simple solution would be for tshy to symlink the current package into
The main downside with that approach is that all of the code in |
Personally, I'm just living with |
Hey Isaac, thanks for the exhaustive answer, appreciate you taking the time to explain why it's not possible. I'm likely going to do the same to be honest, it seems the most straightforward option. I'll close the issue! |
See also #2, which would leverage node's built-in |
Does this assume that people using this tool will be writing ESM-first and not CJS-first? |
Neither is "first" to tshy, they're both just dialects. But it is designed with the expectation that you'll be building for both, and writing tests and other random scripts in ESM rather than CommonJS, not for any reason than that's a bit more convenient usually, and what I personally prefer. The only objective benefit really is that ESM can import CommonJS easily and not the other way around, though I also just find it more subjectively appealing. To be honest, I feel like "there's an extension on my |
Hi, thanks a lot for creating this package. I saw your tweet yesterday and then another from @atcb here and needless to say I'm very interested.
I'm trying to setup dual bundling on a medium size monorepo and I'm unsure how to go around using relative paths and whether or not the project supports the
baseUrl
directive in thetsconfig.json
file.I was able to successfully build one of my packages using tshy using file extensions, i.e. given the following three files:
However I was wondering if it'd be possible and in the scope of the project to support the usage of
baseUrl
. SettingbaseUrl
to './src' would allow me to avoid relative paths altogether and the IDE seems to be fine with that.I have tried using the property in my tsconfig but I think it's ignored at build time and I the build fails.
Thanks :D
The text was updated successfully, but these errors were encountered: