question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[@babel/preset-typescript] Namespace alias (native TS feature) is not supported

See original GitHub issue

Bug Report

  • I would like to work on a fix!

import RenamedModule = OriginalModule is native Typescript’s feature for creating module alias but @babel/preset-typescript does not allow this syntax.

Current behavior

@babel/preset-typescript gives an error.

Error: `import =` is not supported by @babel/plugin-transform-typescript
Please consider using `import <moduleName> from '<moduleName>';` alongside Typescript's --allowSyntheticDefaultImports option.

Input Code

declare module LongNameModule {
  export type SomeType = number;
}
import AliasModule = LongNameModule;

const some: AliasModule.SomeType = 3;
console.log(some);

Expected behavior

It outputs: 3.

Using tsc and ts-node, it is compiled as expected.

Babel Configuration (babel.config.js, .babelrc, package.json#babel, cli command, .eslintrc)

  • Filename: babel.config.js
{
  presets: [
    [
      '@babel/env',
      {
        modules: false,
        targets: {
          esmodules: true,
        },
      },
    ],
    [
      '@babel/typescript',
      {
        allowDeclareFields: true,
      },
    ],
  ],
};

Environment

  • Babel version: v7.12.3
  • Node/npm version: Node 14/yarn 1.22.10
  • OS: alpine linux (in docker)
  • Monorepo: no
  • How you are using Babel: cli

Possible Solution

I have no idea.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:3
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

9reactions
nicolo-ribaudocommented, Feb 1, 2021

This is something that we can support. When we wrote those docs, what we wanted to disallow was import foo = require("...") and export =. import foo = bar is a different feature that has nothing to do with ESM (it just re-uses the keyword).

5reactions
ortycommented, Apr 20, 2021

Hi,

Is there any news regarding this ? I looked around for a plugin to use as a workaround until Babel support namespace aliases but no luck 😦

Read more comments on GitHub >

github_iconTop Results From Across the Web

@babel/preset-typescript | Yarn - Package Manager
Intro. Babel is a tool that helps you write code in the latest version of JavaScript. When your supported environments don't support certain...
Read more >
Why babel alias did not work when set up was all correct?
Specify the root path in your Babel config. For .js Babel config files, we need to use require.resolve('babel-plugin-module-resolver') ...
Read more >
babel/types
Aliases : Standardized , Scopable , Function , BlockParent , FunctionParent ... specifiers : Array<ExportSpecifier | ExportNamespaceSpecifier> (default: null ) ...
Read more >
Namespace aliases - cppreference.com
The new alias alias_name provides an alternate method of accessing ns_name. alias_name must be a name not previously used. alias_name is valid ...
Read more >
Typescript - Notes
There are different ways to set up TypeScript support for the webpack based ... @babel/preset-typescript - babel preset for the TypeScript type checking ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found