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.

error when use in typescript

See original GitHub issue

Which OS ?

win7 64bit

Version

Which versions are you using:

  • react-native-swiper V1.5.13
  • react-native v0.49.3
  • typescript v2.5.3

I got error when use with typescript:

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.

tsconfig.json

{
  "compilerOptions": {
    "target": "es6",        
    "module": "commonjs",   
    "jsx": "react",         
    "sourceMap": true,      
    "outDir": "./lib",      
  },
  "include": ["./src/"]
}

when i write a simple component:

import * as React from 'react';
import Swiper from 'react-native-swiper'; // import default
import {View,Image} from 'react-native';
const Test =()=>(
    <Swiper loop={false}>
        <View >
            <Image source={require(`../../images/test1.png`)}></Image>
        </View>
        <View >
            <Image source={require(`../../images/test2.png`)}></Image>
        </View>
    </Swiper>
)
export default Test;

the result after tsc compile is:

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const React = require("react");
const react_native_swiper_1 = require("react-native-swiper");
const react_native_1 = require("react-native");
const Test = () => (React.createElement(react_native_swiper_1.default, { loop: false },
    React.createElement(react_native_1.View, null,
        React.createElement(react_native_1.Image, { source: require(`../../images/test1.png`) })),
    React.createElement(react_native_1.View, null,
        React.createElement(react_native_1.Image, { source: require(`../../images/test2.png`) }))));
exports.default = Test;
//# sourceMappingURL=test.js.map

you can see that, in compiled js code use React.createElement(react_native_swiper_1.default, { loop: false }create Swiper component,but actually react_native_swiper_1 is the valid component,while react_native_swiper_1.default is undefined,Because in index.js:

import Swiper from './src/'
module.exports = Swiper

I see the PR #393 resolved the problem. so why not use it?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
nikolasleblanccommented, Nov 14, 2017

You can just import from ‘react-native-swiper/src’ for now.

2reactions
sunny635533commented, Nov 2, 2017

In node_modules/react-native-swiper has index.d.ts,but its version is old.When we use “npm install @types/react-native-swiper”, could get the latest d.ts. However our project with typescript only check the old d.ts, so please change the old d.ts with another name,not " index.d.ts",or update its type as the latest d.ts.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Get a catch block error message with TypeScript - Kent C. Dodds
TypeScript forces you to acknowledge you can't know what was thrown making getting the error message a pain. Here's how you can manage...
Read more >
Documentation - Understanding Errors - TypeScript
Whenever TypeScript finds an error, it tries to explain what went wrong in as much detail as possible. Because its type system is...
Read more >
Improving TypeScript error handling with exhaustive type ...
In this article, we'll cover a few of the most common approaches for error handling in TypeScript (TS). We'll talk about most common...
Read more >
Exception Handling - TypeScript Deep Dive - Gitbook
JavaScript has an Error class that you can use for exceptions. You throw an error with the throw keyword. You can catch it...
Read more >
Type-Safe Error Handling In TypeScript - DEV Community ‍ ‍
First, let's begin by acknowledging that throw is not typesafe. We must use a different approach in order to get the TypeScript compiler...
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