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.

Typescript runtime issues

See original GitHub issue

When I embed this using in an ES6 JSX file, this works fine. I am using Webpack 1 and Typescript.

However, using TypeScript, I get this error (at runtime):

Warning: React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in. Check the render method of `Test`.

This is my Test component:

import * as React from 'react';
import { render } from 'react-dom';
import Dropzone from 'react-dropzone';
interface TestProps {

}
export default class Test extends React.Component<TestProps, {}> {

  render(){
    return(
       <Dropzone onDrop={() => console.log("drop")}>
              <div>Try dropping some files here, or click to select files to upload.</div>
        </Dropzone>
    )
  }

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:24

github_iconTop GitHub Comments

8reactions
goloveychukcommented, Nov 24, 2017

@dupski solution:

  1. make all imports import * as Dropzone from 'react-dropzone/dist/index';
  2. add react-dropzone.d.ts react-dropzone.txt

This is because https://github.com/react-dropzone/react-dropzone/blob/master/package.json#L4-L5 webpack using module, typescript main. In first file we have export default, on second - module.exports = {} Why typescript using main? I guess because of https://github.com/goloveychuk/ts-jest/blob/master/src/utils.ts#L208-L213 Not 100% sure.

5reactions
YGKtechcommented, Nov 27, 2017

I’m facing this issue too, the problem has not been resolved and this issue should be reopened.

Currently the only way I’ve been able to use this in typescript is to not install the @types definiton, change my tsconfig.json to allow implicit any statements, then import it as import * as Dropzone from 'react-dropzone'; and reference the component as <Dropzone.default>

This is a lot of hassle to go through for a single component, and the workaround isn’t documented anywhere.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to make Typescript throw runtime error? - Stack Overflow
Typescript knows nothing of runtime. It's a compiler. There may be a way to get Angular (which does exist at runtime) to do...
Read more >
Take control of unexpected data at runtime with TypeScript
In this article, we'll explore how to use TypeScript type definitions to get better guarantees for runtime safety.
Read more >
Say Goodbye to JavaScript runtime type errors with TypeScript
Are you exhausted with JavaScript runtime type errors and you can't give up JavaScript? The perfect solution is TypeScript.
Read more >
Runtime type checking · Issue #1573 · microsoft/TypeScript
I request a runtime type checking system that perhaps looks something like this: function square(x: number!) { return x * x; } Where...
Read more >
Catching Runtime Errors in Compile Time with Typescript
The problem. After the lengthy intro, a little heads up - WebGL 2.0 API ...
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