Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[preset-typescript] cannot named export interface #10360

Open
ApolloTang opened this issue Aug 22, 2019 · 4 comments

Comments

@ApolloTang
Copy link

commented Aug 22, 2019

Bug Report

The following works:

import React from 'react'

export interface Props {
  textToShow?: React.ReactNode
  children?: React.ReactNode
}

const MyComponent = (props:Props) => (
  <div>
    { props.textToShow && <div> {props.textToShow} </div> }
  </div>
)

export {MyComponent}

However, if I named export interface Props like so:

import React from 'react'

interface Props {
  textToShow?: React.ReactNode
  children?: React.ReactNode
}

const MyComponent = (props:Props) => (
  <div>
    { props.textToShow && <div> {props.textToShow} </div> }
  </div>
)

export {Props, MyComponent}

Failed with errors:

Screen Shot 2019-08-22 at 1 12 33 AM

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

module.exports = (api) => {
  api.cache(true)
  const presets = [
    [
      '@babel/preset-env',
      {
        'debug': false,
        'targets': {'ie':'11'},
        'useBuiltIns': 'usage',
        // 'corejs': 3,  // dynamic import is broken:
                         // https://github.com/babel/babel/issues/9872
                         // so we will use corejs@2 instead
        'corejs': 2,
        'modules': false
      }
    ],
    '@babel/preset-typescript',
    '@babel/preset-react',
  ]

  const plugins = [
    '@babel/proposal-class-properties',
    '@babel/plugin-syntax-dynamic-import',
  ].filter(Boolean)

  return {
    presets,
    plugins
  }
}
  "engines": {
    "node": "10"
  },
  "devDependencies": {
    "@babel/cli": "^7.5.5",
    "@babel/core": "^7.5.5",
    "@babel/plugin-proposal-class-properties": "^7.5.5",
    "@babel/preset-env": "^7.5.5",
    "@babel/preset-react": "^7.0.0",
    "@babel/preset-typescript": "^7.3.3",
    "@types/node": "^12.7.2",
    "@types/react": "^16.9.2",
    "@types/react-dom": "^16.8.5",
    "@typescript-eslint/eslint-plugin": "^2.0.0",
    "@typescript-eslint/parser": "^2.0.0",
    "babel-eslint": "^10.0.2",
    "babel-loader": "^8.0.6",
    "babel-plugin-dynamic-import-node": "^2.3.0",
    "eslint": "^6.2.0",
    "eslint-plugin-react": "^7.14.3",
    "eslint-plugin-react-hooks": "^1.7.0",
    "find-free-port": "^2.0.0",
    "html-webpack-plugin": "^3.2.0",
    "typescript": "^3.5.3",
    "webpack": "^4.39.2",
    "webpack-cli": "^3.3.7",
    "webpack-dev-server": "^3.8.0"
  },
  "dependencies": {
    "core-js": "2",
    "react": "^16.9.0",
    "react-dom": "^16.9.0",
    "regenerator-runtime": "^0.13.3"
  },

Environment

  • Babel version(s): v7.5.5
  • Node/npm version: Node 10
  • OS: OSX 10.14.6
  • How you are using Babel: loader
@babel-bot

This comment has been minimized.

Copy link
Collaborator

commented Aug 22, 2019

Hey @ApolloTang! We really appreciate you taking the time to report an issue. The collaborators on this project attempt to help as many people as possible, but we're a limited number of volunteers, so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack community that typically always has someone willing to help. You can sign-up here for an invite.

@ApolloTang

This comment has been minimized.

Copy link
Author

commented Aug 22, 2019

@nicolo-ribaudo

This comment has been minimized.

Copy link
Member

commented Aug 22, 2019

What does npx nls why @babel/parser print? I think that for some reason it's using an older version

@ApolloTang

This comment has been minimized.

Copy link
Author

commented Aug 22, 2019

@nicolo-ribaudo

$ npx nls why @babel/parser
npx: installed 8 in 1.347s

  Who required @babel/parser:

  b06 > @babel/core > @babel/helpers > @babel/template > @babel/parser@^7.4.4
  b06 > @babel/core > @babel/helpers > @babel/traverse > @babel/helper-function-name > @babel/template > @babel/parser@^7.2.2
  b06 > @babel/core > @babel/helpers > @babel/traverse > @babel/parser@^7.5.5
  b06 > @babel/core > @babel/parser@^7.5.5
  b06 > @babel/core > @babel/template > @babel/parser@^7.4.4
  b06 > @babel/core > @babel/traverse > @babel/helper-function-name > @babel/template > @babel/parser@^7.2.2
  b06 > @babel/core > @babel/traverse > @babel/parser@^7.5.5
  b06 > @babel/plugin-proposal-class-properties > @babel/helper-create-class-features-plugin > @babel/helper-function-name > @babel/template > @babel/parser@^7.2.2
  b06 > @babel/plugin-proposal-class-properties > @babel/helper-create-class-features-plugin > @babel/helper-replace-supers > @babel/traverse > @babel/helper-function-name > @babel/template > @babel/parser@^7.2.2
  b06 > @babel/plugin-proposal-class-properties > @babel/helper-create-class-features-plugin > @babel/helper-replace-supers > @babel/traverse > @babel/parser@^7.5.5
  b06 > @babel/preset-env > @babel/plugin-proposal-async-generator-functions > @babel/helper-remap-async-to-generator > @babel/helper-wrap-function > @babel/helper-function-name > @babel/template > @babel/parser@^7.2.2
  b06 > @babel/preset-env > @babel/plugin-proposal-async-generator-functions > @babel/helper-remap-async-to-generator > @babel/helper-wrap-function > @babel/template > @babel/parser@^7.2.2
  b06 > @babel/preset-env > @babel/plugin-proposal-async-generator-functions > @babel/helper-remap-async-to-generator > @babel/helper-wrap-function > @babel/traverse > @babel/helper-function-name > @babel/template > @babel/parser@^7.2.2
  b06 > @babel/preset-env > @babel/plugin-proposal-async-generator-functions > @babel/helper-remap-async-to-generator > @babel/helper-wrap-function > @babel/traverse > @babel/parser@^7.3.4
  b06 > @babel/preset-env > @babel/plugin-proposal-async-generator-functions > @babel/helper-remap-async-to-generator > @babel/template > @babel/parser@^7.2.2
  b06 > @babel/preset-env > @babel/plugin-proposal-async-generator-functions > @babel/helper-remap-async-to-generator > @babel/traverse > @babel/helper-function-name > @babel/template > @babel/parser@^7.2.2
  b06 > @babel/preset-env > @babel/plugin-proposal-async-generator-functions > @babel/helper-remap-async-to-generator > @babel/traverse > @babel/parser@^7.3.4
  b06 > @babel/preset-env > @babel/plugin-transform-async-to-generator > @babel/helper-remap-async-to-generator > @babel/helper-wrap-function > @babel/helper-function-name > @babel/template > @babel/parser@^7.2.2
  b06 > @babel/preset-env > @babel/plugin-transform-async-to-generator > @babel/helper-remap-async-to-generator > @babel/helper-wrap-function > @babel/template > @babel/parser@^7.2.2
  b06 > @babel/preset-env > @babel/plugin-transform-async-to-generator > @babel/helper-remap-async-to-generator > @babel/helper-wrap-function > @babel/traverse > @babel/helper-function-name > @babel/template > @babel/parser@^7.2.2
  b06 > @babel/preset-env > @babel/plugin-transform-async-to-generator > @babel/helper-remap-async-to-generator > @babel/helper-wrap-function > @babel/traverse > @babel/parser@^7.3.4
  b06 > @babel/preset-env > @babel/plugin-transform-async-to-generator > @babel/helper-remap-async-to-generator > @babel/template > @babel/parser@^7.2.2
  b06 > @babel/preset-env > @babel/plugin-transform-async-to-generator > @babel/helper-remap-async-to-generator > @babel/traverse > @babel/helper-function-name > @babel/template > @babel/parser@^7.2.2
  b06 > @babel/preset-env > @babel/plugin-transform-async-to-generator > @babel/helper-remap-async-to-generator > @babel/traverse > @babel/parser@^7.3.4
  b06 > @babel/preset-env > @babel/plugin-transform-classes > @babel/helper-define-map > @babel/helper-function-name > @babel/template > @babel/parser@^7.2.2
  b06 > @babel/preset-env > @babel/plugin-transform-classes > @babel/helper-function-name > @babel/template > @babel/parser@^7.2.2
  b06 > @babel/preset-env > @babel/plugin-transform-classes > @babel/helper-replace-supers > @babel/traverse > @babel/helper-function-name > @babel/template > @babel/parser@^7.2.2
  b06 > @babel/preset-env > @babel/plugin-transform-classes > @babel/helper-replace-supers > @babel/traverse > @babel/parser@^7.5.5
  b06 > @babel/preset-env > @babel/plugin-transform-exponentiation-operator > @babel/helper-builder-binary-assignment-operator-visitor > @babel/helper-explode-assignable-expression > @babel/traverse > @babel/helper-function-name > @babel/template > @babel/parser@^7.2.2
  b06 > @babel/preset-env > @babel/plugin-transform-exponentiation-operator > @babel/helper-builder-binary-assignment-operator-visitor > @babel/helper-explode-assignable-expression > @babel/traverse > @babel/parser@^7.3.4
  b06 > @babel/preset-env > @babel/plugin-transform-function-name > @babel/helper-function-name > @babel/template > @babel/parser@^7.2.2
  b06 > @babel/preset-env > @babel/plugin-transform-modules-amd > @babel/helper-module-transforms > @babel/helper-simple-access > @babel/template > @babel/parser@^7.2.2
  b06 > @babel/preset-env > @babel/plugin-transform-modules-amd > @babel/helper-module-transforms > @babel/template > @babel/parser@^7.2.2
  b06 > @babel/preset-env > @babel/plugin-transform-modules-commonjs > @babel/helper-module-transforms > @babel/helper-simple-access > @babel/template > @babel/parser@^7.2.2
  b06 > @babel/preset-env > @babel/plugin-transform-modules-commonjs > @babel/helper-module-transforms > @babel/template > @babel/parser@^7.4.4
  b06 > @babel/preset-env > @babel/plugin-transform-modules-commonjs > @babel/helper-simple-access > @babel/template > @babel/parser@^7.2.2
  b06 > @babel/preset-env > @babel/plugin-transform-modules-umd > @babel/helper-module-transforms > @babel/helper-simple-access > @babel/template > @babel/parser@^7.2.2
  b06 > @babel/preset-env > @babel/plugin-transform-modules-umd > @babel/helper-module-transforms > @babel/template > @babel/parser@^7.2.2
  b06 > @babel/preset-env > @babel/plugin-transform-object-super > @babel/helper-replace-supers > @babel/traverse > @babel/helper-function-name > @babel/template > @babel/parser@^7.2.2
  b06 > @babel/preset-env > @babel/plugin-transform-object-super > @babel/helper-replace-supers > @babel/traverse > @babel/parser@^7.5.5
  b06 > @babel/preset-env > @babel/plugin-transform-parameters > @babel/helper-call-delegate > @babel/traverse > @babel/helper-function-name > @babel/template > @babel/parser@^7.2.2
  b06 > @babel/preset-env > @babel/plugin-transform-parameters > @babel/helper-call-delegate > @babel/traverse > @babel/parser@^7.5.5
  b06 > babel-eslint > @babel/parser@^7.0.0
  b06 > babel-eslint > @babel/traverse > @babel/helper-function-name > @babel/template > @babel/parser@^7.2.2
  b06 > babel-eslint > @babel/traverse > @babel/parser@^7.5.5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.