brigand / brigand/babel-plugin-flow-react-proptypes

Importing type from local file is left unresolved by rollup

Open
#157 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
427
Forks
42
PR merge metrics
No merged PRs in 30d

Description

In ComponentA.js:
```js
...
export type ComponentAType = string
...
```

This gets transpiled with the plugin to:
```js
var babelPluginFlowReactPropTypes_proptype_ComponentAType$1 = require('prop-types').string;

if (typeof exports !== 'undefined') Object.defineProperty(exports, 'babelPluginFlowReactPropTypes_proptype_ComponentAType', {
value: babelPluginFlowReactPropTypes_proptype_ComponentAType$1,
configurable: true
});
```

Now in ComponentB.js:
```js
...
import type { ComponentAType } from './ComponentA'
...
```

This gets transpiled with the plugin to:
```js
var babelPluginFlowReactPropTypes_proptype_ComponentAType = require('./ComponentA').babelPluginFlowReactPropTypes_proptype_ComponentAType || require('prop-types').any;
```

This `require('./ComponentA')` doesn't seem to get picked up by rollup, making it break bundled builds. Not sure if this is actually fixable in this plugin, since I would think it's rollup's job to figure how the `require()`s should be linked, but wondering if anyone's solved this before or if this also happens with webpack?

My rollup.config.js currently includes these plugins:
```js
babel({ exclude: 'node_modules/**', plugins: ['external-helpers'] }),
resolve(),
commonjs(),
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.