Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CommonJS and AMD module names are different #399

Closed
elektromodulator opened this issue Jul 1, 2016 · 15 comments
Closed

CommonJS and AMD module names are different #399

elektromodulator opened this issue Jul 1, 2016 · 15 comments
Milestone

Comments

@elektromodulator
Copy link

elektromodulator commented Jul 1, 2016

CommonJS module name is "interact.js" (as defined in package.json), but AMD module name is "interact".
I think it should be consistent in all environment.
This also creates a problem in language bindings, as module name is dependent on the environment.
For example in DefinitelyTyped's interact.d.ts it is defined as "interact.js", which makes it unusable for browser projects.

@taye
Copy link
Owner

taye commented Aug 10, 2016

I initially didn't want to publish to npm at all and just tell people point to the git repo but people convinced me otherwise in #118. Unfortunately interact was taken on npm so I went with interact.js.

@elektromodulator
Copy link
Author

I understand, but in TypeScript, you must statically define the module name, so this module name discrepancy is an issue. At DefinitelyTyped project the convention is to use the npm package name as module name, but this makes it unusable in browser.

@unsalted
Copy link

the npm name interact.js also conflicts with bundlers like the ones used in aurelia because it assumes it's looking for a js file instead of an npm module

@elektromodulator
Copy link
Author

elektromodulator commented Nov 1, 2016

@taye: Are you willing to make the CommonJS module name and AMD module name consistent, and maybe also fix the problem @unsalted mentioned?

@taye
Copy link
Owner

taye commented Nov 28, 2016

I'll see if @chrisdickinson would be okay with giving us the interact package name. If he's not, what do you think would be a good alternative to use?

@unsalted
Copy link

unsalted commented Nov 28, 2016 via email

@taye
Copy link
Owner

taye commented Nov 30, 2016

[email protected] has been released. Aside from the package name, It's identical to v1.2.6.

@elektromodulator
Copy link
Author

My original issue is still not resolved though: AMD module name is still interact, and not interactjs like the CommonJS module name.

@taye taye reopened this Dec 9, 2016
@taye taye added this to the v1.3.0 milestone Jan 27, 2017
@taye
Copy link
Owner

taye commented Feb 2, 2017

I've exchanged some emails with [email protected]. Something should happen soon maybe.

@taye
Copy link
Owner

taye commented Feb 2, 2017

@elektromodulator, @machineghost The trendy thing seems to be to use an "@" in the module name if there's a conflict. Since Angular does this and is written in TypeScript, I presume that this would be an optimal solution. window['@interact'] for people who don't use a module loader doesn't look great so I guess I'll also assign to window.interact. Do you see any potential issues?

@elektromodulator
Copy link
Author

elektromodulator commented Feb 3, 2017

"@" starting names are scope names in NPM.
I think the "@angular/XYZ" module name means that XYZ module in angular namespace/scope.
In interact's case we only have one package.

@taye
Copy link
Owner

taye commented Feb 5, 2017

How does your setup handle anonymous AMD modules and would that be an appropriate solution?

@taye
Copy link
Owner

taye commented Feb 5, 2017

I just noticed that the unstable build (which is bundled using browserify with the 'standalone' option set to 'interact') assigns to window.interact in a plain browser environment but defines itself anonymously if there's an AMD define function. Can you try the unstable branch to see how that works?

@elektromodulator
Copy link
Author

I'll try it tomorrow, if I have the time (too busy lately :( ).
I think that may be a good solution since in case of anonymous modules, you can map it to any name you want (at least in require.js).

@lddubeau
Copy link
Contributor

The inconsistency problem between AMD and CommonJS names could have been solved without renaming the project. If someone is working with code that assumed the CommonJS name and then must work in an AMD environment, it can be solved with a map configuration in RequireJS:

map: {
  "*": {
    "interact.js": "interact",
  }
}

This means "everywhere where someone requests the module named interact.js, load interact instead."

SystemJS also supports making such mapping.

The reverse mapping would also be possible if someone started using the AMD name and the must work with the CommonJS name.


Ultimately, it would be preferable to just avoid hardcoding the name in the define call. Hardcoding the name is generally not recommended, and it does cause problems that could be avoided if a name was not hardcoded. Conversely, I've never ever encountered a situation where solving a problem with loading AMD modules demanded that a third-party library get a hardcoded name.

@taye taye closed this as completed Nov 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants