jaredhanson / jaredhanson/deamdify

Variable `module` inside module breaks deamdify

Open
#4 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
196
Forks
29
PR merge metrics
No merged PRs in 30d

Description

Let's say I have two files

a.js

``` js
define(function () {
var module = {
t: function () {
console.log('a');
}
};
return module;
});
```

b.js

``` js
define(['./a'], function (a) {
a.t();
});
```

Then `browserify -t deamdify b.js -o bundle.js` yields

``` js
...

var module = {
t: function () {
console.log('a');
}
};
module.exports = module;

...
```

Importing that in node throws an error:

``` sh
$ node
> require('./bundle')
TypeError: Object # has no method 't'
at Object../a (/private/tmp/amd/bundle.js:10:3)
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Reproduce the issue with the shown a.js and b.js files by running browserify -t deamdify b.js -o bundle.js and requiring the result in Node. Then inspect deamdify's AMD-to-CommonJS transform and verify that a local variable named module does not replace the exported module object, while a.t() still works.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.