Andarist / Andarist/use-latest

React import style causes issues with build

Aperta
#6 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
TypeScript
Stelle
20
Fork
5
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

I'm importing `use-latest` through `react-textarea-autosize` in a React library that gets built with rollup. The importing package (`pkg-a`) works and builds fine but packages that import that package (`pkg-b`) are unable to run and crash with the error:

```
TypeError: Cannot read property 'default' of undefined

> 10 | */"production"!==process.env.NODE_ENV&&function(){var e=t,n=Symbol.for("react.element"),r=Symbol.for("react.portal"),o=Symbol.for("react.fragment"),i=Symbol.for("react.strict_mode"),a=Symbol.for("react.profiler") [...]
| ^
```

After adding `react-textarea-autosize`, the beginning of the built dist file changes from:

```
import e,{Component as t}from"react";
```

to:

```
import*as e from"react";import t,{Component as n,useLayoutEffect as r,useEffect as o,useRef as i,useCallback as a,forwardRef as s,createElement as l}from"react";
```

I've narrowed the issue down to this package (`use-latest`), and specifically the React import line:

```
import * as React from 'react'
```

The issue is resolved by changing the line to either:

```
import React from 'react'
```

or:

```
import { useRef } from 'react'
```

I believe the latter change is more in the style of your packages.

I will submit a PR shortly.

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.