jaredpalmer / jaredpalmer/backpack
CommonJS-Modules containing an async function are empty when required
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 4.4k
- Forks
- 164
- PR merge metrics
- No merged PRs in 30d
Description
Hi,
I just started to integrate backpack and it seems quite nice, but I encountered the following problem:
When a CommonJS module with an async function is required, the imported object is empty.
Test case:
a.js
```js
exports.x = () => 5 // normal function
```
b.js
```js
exports.x = async () => 5 // async function
```
c.js
```js
export const x = async () => 5 // async function
```
index.js
```js
const a = require('./a')
const b = require('./b')
import {x} from './c'
console.log('a', a) // normal function in CommonJS module ==> works
console.log('b', b) // async function in CommonJS module ==> doesn't work
console.log('c', x) // async function in ES6 module ==> works
```
Output
```
a { x: [Function] }
b {}
c function x() {
return _ref.apply(this, arguments);
}
```
Notice that the object after `b` is empty, so the exported functions are not callable. Strange is that the aysnc function works when imported from an ES6 module.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the issue with the a.js, b.js, c.js, and index.js examples from the report, then inspect Backpack's JavaScript module build path. Compare the required exports for the normal and async CommonJS cases; done means requiring b.js exposes x as a callable function like the other examples.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- babel, javascript, node.js, webpack
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100