1

Sorry for the super newbie vague question, but can I do

import {Component} from 'react'

class MyComponent extends Component { ..

rather than

import * as React from 'react` 

class MyComponent extends React.Component { ..

in babel/webpack/typescript/react ish environment?

If not, why's that?

My webpack.config.json is looking like this.

module: {
  rules: [
    {
      test: /\.js$/,
      use: ['babel-loader', 'source-map-loader'],
      exclude: /node_modules/
    },
    {
      test: /\.tsx?$/,
      exclude: /node_modules/,
      loader: 'happypack/loader?id=ts'
    },

...

plugins: [
  new HappyPack({
    id: 'ts',
    threads: 2,
    loaders: [
      {
        path: 'ts-loader',
        query: { happyPackMode: true }
      }
    ]
  }),

...
4
  • 1
    This appears to be a duplicate of stackoverflow.com/questions/41768205/…, which is a duplicate of stackoverflow.com/questions/31096597/… Commented Oct 28, 2017 at 22:38
  • 1
    What happens if you try...? Commented Oct 28, 2017 at 22:38
  • it shows the message TS2686: 'React' refers to a UMD global, but the current file is a module. Consider adding an import instead. Commented Oct 28, 2017 at 22:42
  • 6
    This is not a duplicate. Typescript, by default, does not allow the named imports to be used with many react packages... Commented Jun 25, 2018 at 14:10

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.