You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've encountered some import path issues when using tsup with bundle: false. Specifically, the problems are:
Missing File Extensions: When bundle: false is set, the output files sometimes have import statements without explicit file extensions (like .js, .mjs, or .cjs). This can cause runtime errors in environments that require explicit file extensions.
Directory Imports: Importing from directories without specifying the index file (e.g., import { something } from './utils';) can lead to module resolution issues because some environments don't automatically resolve to index files.
Unresolved Path Aliases: Path aliases defined in tsconfig.json aren't correctly resolved in the output when not bundling, resulting in broken imports.
To address these issues, I created a package called esbuild-fix-imports-plugin that combines three ESBuild plugins to modify the output files:
fixAliasPlugin: Resolves path aliases from tsconfig.json to relative paths.
fixFolderImportsPlugin: Converts directory imports to explicit paths pointing to index files.
fixExtensionsPlugin: Appends correct file extensions to relative import paths.
Suggestion:
Would it be possible to integrate similar fixes directly into tsup when bundle: false is used? This could greatly enhance the developer experience by:
Automatically appending the correct file extensions to imports in the output.
Resolving path aliases defined in tsconfig.json.
Adjusting directory imports to explicitly reference index files.
Example of the Issues:
Given a source file with:
import{myFunction}from'./utils';// Importing using folder pathimport{myFunction}from'./utils/myFunction';// Importing using file pathimport{myAliasFunction}from'@alias/utils/myFunction';// Importing using alias
After building with tsup and bundle: false, the output might contain:
This can cause runtime errors due to unresolved imports.
Proposed Solution:
Integrate logic similar to the plugins in esbuild-fix-imports-plugin to process the output files when bundle: false is set. This could be an opt-in feature or enabled by default when not bundling.
Alternative:
If direct integration isn't feasible, perhaps the documentation could mention this issue and recommend using esbuild-fix-imports-plugin or similar solutions.
Additional Context:
Here's how I currently use the plugin with tsup:
import{defineConfig}from'tsup';import{fixImportsPlugin}from'esbuild-fix-imports-plugin';exportdefaultdefineConfig({// Other configurationsbundle: false,esbuildPlugins: [fixImportsPlugin()],// ...});
Hi,
First, thank you for the fantastic work on
tsup
!I've encountered some import path issues when using
tsup
withbundle: false
. Specifically, the problems are:Missing File Extensions: When
bundle: false
is set, the output files sometimes have import statements without explicit file extensions (like.js
,.mjs
, or.cjs
). This can cause runtime errors in environments that require explicit file extensions.Directory Imports: Importing from directories without specifying the
index
file (e.g.,import { something } from './utils';
) can lead to module resolution issues because some environments don't automatically resolve toindex
files.Unresolved Path Aliases: Path aliases defined in
tsconfig.json
aren't correctly resolved in the output when not bundling, resulting in broken imports.To address these issues, I created a package called
esbuild-fix-imports-plugin
that combines three ESBuild plugins to modify the output files:fixAliasPlugin
: Resolves path aliases fromtsconfig.json
to relative paths.fixFolderImportsPlugin
: Converts directory imports to explicit paths pointing toindex
files.fixExtensionsPlugin
: Appends correct file extensions to relative import paths.Suggestion:
Would it be possible to integrate similar fixes directly into
tsup
whenbundle: false
is used? This could greatly enhance the developer experience by:tsconfig.json
.index
files.Example of the Issues:
Given a source file with:
After building with
tsup
andbundle: false
, the output might contain:This can cause runtime errors due to unresolved imports.
Proposed Solution:
Integrate logic similar to the plugins in
esbuild-fix-imports-plugin
to process the output files whenbundle: false
is set. This could be an opt-in feature or enabled by default when not bundling.Alternative:
If direct integration isn't feasible, perhaps the documentation could mention this issue and recommend using
esbuild-fix-imports-plugin
or similar solutions.Additional Context:
Here's how I currently use the plugin with
tsup
:References:
Thank you for considering this suggestion!
Best regards,
Upvote & Fund
The text was updated successfully, but these errors were encountered: