[@babel/preset-typescript] Namespace alias (native TS feature) is not supported
See original GitHub issueBug 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:
- Created 3 years ago
- Reactions:3
- Comments:8 (3 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This is something that we can support. When we wrote those docs, what we wanted to disallow was
import foo = require("...")
andexport =
.import foo = bar
is a different feature that has nothing to do with ESM (it just re-uses the keyword).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 😦