I am trying to make a NPM package using Typescript and React. (TSX)
I am following this blog post, but trying to make multiple components instead of just one.
When I try and import my module like this
import { HelloWorld } from 'tsx_lib'
It shows up as undefined
console.log(HelloWorld) //undefined
My folder structure looks like this
src /
GoodbyeWorld.tsx
HelloWorld.tsx
index.ts
index.d.ts
Here are the files
GoodbyeWorld.tsx
import * as React from 'react';
import { GoodbyeWorldProps } from '../index';
export default class GoodbyeWorld extends React.Component<any, any> {
render() {
return <div style={{ color: this.props.color }}>Goodbye world!</div>;
}
}
HelloWorld.tsx
import * as React from 'react';
import { HelloWorldProps } from '../index';
export default class HelloWorld extends React.Component<any, any> {
render() {
return <div style={{ color: this.props.color }}>Hello world!</div>;
}
}
index.ts
export * from './HelloWorld';
export * from './GoodbyeWorld';
index.d.ts
import * as React from 'react';
export interface HelloWorldProps extends React.Props<HelloWorld> {
color: string;
}
export interface GoodbyeWorldProps extends React.Props<HelloWorld> {
color: string;
}
declare module 'hello-world' {
}
declare module 'goodbye-world' {
}
export class HelloWorld extends React.Component<HelloWorldProps, any> {}
export class GoodbyeWorld extends React.Component<HelloWorldProps, any> {}
What am I doing wrong?
import HelloWorld from 'tsx_lib'without brackets, if you export it asdefaultmodule, you need to import it without brackets