Skip to content

Typescript import = is not supported. #7062

@rosskevin

Description

@rosskevin

Choose one: is this a bug report or feature request?
Bug (or feature - because typescript support is new)

Input Code

import debounce = require('lodash/debounce')

Babel/Babylon Configuration (.babelrc, package.json, cli command)

{
  "presets": [
    "@babel/preset-typescript",
    "@babel/preset-env",
    "@babel/preset-stage-1",
    "@babel/preset-react"
  ]
} 

Expected Behavior

From https://www.typescriptlang.org/docs/handbook/modules.html#export--and-import--require

When importing a module using export =, TypeScript-specific import module = require("module") must be used to import the module.

Current Behavior

SyntaxError: src/transitions/Slide.tsx: `import =` is not supported.

    at File.buildCodeFrameError (/Users/kross/projects/material-ui/node_modules/@babel/core/lib/transformation/file/file.js:209:12)
    at NodePath.buildCodeFrameError (/Users/kross/projects/material-ui/node_modules/@babel/traverse/lib/path/index.js:155:26)
    at PluginPass.TSImportEqualsDeclaration (/Users/kross/projects/material-ui/node_modules/@babel/plugin-transform-typescript/lib/index.js:208:20)
    at newFn (/Users/kross/projects/material-ui/node_modules/@babel/traverse/lib/visitors.js:223:21)
    at NodePath._call (/Users/kross/projects/material-ui/node_modules/@babel/traverse/lib/path/context.js:64:19)
    at NodePath.call (/Users/kross/projects/material-ui/node_modules/@babel/traverse/lib/path/context.js:38:17)
    at NodePath.visit (/Users/kross/projects/material-ui/node_modules/@babel/traverse/lib/path/context.js:99:12)
    at TraversalContext.visitQueue (/Users/kross/projects/material-ui/node_modules/@babel/traverse/lib/context.js:139:18)
    at TraversalContext.visitMultiple (/Users/kross/projects/material-ui/node_modules/@babel/traverse/lib/context.js:93:17)
    at TraversalContext.visit (/Users/kross/projects/material-ui/node_modules/@babel/traverse/lib/context.js:178:19)

Possible Solution

One idea would be that since this is a typescript only concept, and babel handles the other syntax well, just convert

import debounce = require('lodash/debounce')

to

import debounce from 'lodash/debounce'

Context

Cannot use babel 7 directly without tsc preprocessing.

Your Environment

software version(s)
Babel @babel/core@7.0.0-beta.35
node 9.3.0
Operating System OSX

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: typescriptoutdatedA closed issue/PR that is archived due to age. Recommended to make a new issue

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions