Skip to content

Can't control which functional imports are shimmed under rewriteRelativeImportExtensions #62459

Description

Acknowledgement

  • I acknowledge that issues using this template may be closed without further explanation at the maintainer's discretion.

Comment

When using rewriteRelativeImportExtensions, all relative imports with ts extensions are changed to js. This is fine for static imports but, since importing and running ts files is still possible in some environments, this may be problematic or worst, buggy, for functional imports, see this exemple :

// filePath is the path to a file that being listed at runtime and can have a ts extension
if (filePath.endsWith('.ts')) {
	const file = await import(filePath);
	// do something
}

import(filePath) will be unconditionally shimmed here, and it's not a desirable behavior because the shimming process clearly introduces a bug: a ts file will have his extension changed to js, and import() will throw or, even worst, open the js file if it exists (it may be or not the equivalent of the original file).

How to control and/or disable this behavior?

See #59767 for details about rewriteRelativeImportExtensions

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions