Skip to content

[Bug]: @babel/preset-typescript rewriteImportExtensions does not work for dynamic imports #16750

Closed
@lenovouser

Description

How are you using Babel?

@babel/cli

Input code

import * as import1 = from './file1.ts';
const import2 = await import('./file2.ts');

Configuration file name

.babelrc

Configuration

{
    "presets": [
        [
            "@babel/preset-typescript",
            {
                "rewriteImportExtensions": true
            }
        ],
        [
            "@babel/preset-env",
            {
                "targets": {
                    "node": "22"
                },
                "modules": false
            }
        ]
    ]
}

Current and expected behavior

Only regular imports get transformed to .js, dynamic ones keep the .ts extension.

Environment

  System:
    OS: macOS 14.6.1
  Binaries:
    Node: 22.6.0 - /usr/local/bin/node
    Yarn: 1.22.22 - ~/Library/pnpm/yarn
    npm: 10.8.2 - /opt/homebrew/bin/npm
    pnpm: 9.7.1 - ~/Library/pnpm/pnpm
    bun: 1.1.25 - ~/.bun/bin/bun
  npmPackages:
    @babel/cli: 7.24.8 => 7.24.8
    @babel/core: 7.25.2 => 7.25.2
    @babel/plugin-transform-export-namespace-from: 7.24.7 => 7.24.7
    @babel/plugin-transform-react-jsx: 7.25.2 => 7.25.2
    @babel/preset-env: 7.25.3 => 7.25.3
    @babel/preset-typescript: 7.24.7 => 7.24.7
    babel-plugin-root-import: 6.6.0 => 6.6.0

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

    i: needs triageoutdatedA closed issue/PR that is archived due to age. Recommended to make a new issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions