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

Store is undefined when loading into a page that already uses AMD #96

Closed
kgust opened this issue May 27, 2014 · 13 comments
Closed

Store is undefined when loading into a page that already uses AMD #96

kgust opened this issue May 27, 2014 · 13 comments

Comments

@kgust
Copy link

kgust commented May 27, 2014

We tried loading store.js into a site that had require.js (which was outside our control and loaded modules unrelated to what we were doing).

We use window.store to access store. In this case, define.amd was defined so the code tries to call define(store) instead.

Because window.store is not defined, our code doesn't run.

NOTE: This is related to Issue #91 but is a different problem.

@marcuswestin
Copy link
Owner

Yeah, this shit is a clusterfuck.

Do you have a proposed solution?

@marcuswestin
Copy link
Owner

How are you loading store.js? Are you a library provider? Perhaps check if amd is being used (typeof define === 'function' && define.amd) and if it is, load it using require? Or perhaps bundle a custom build of store.js with your library that doesn't have all the silly module checks?

Are you from Sweden by any chance? I am originally, but lived in Chicago for 4 years. Freakin' cold!!

@kgust
Copy link
Author

kgust commented May 27, 2014

At the moment, we are using a custom version (removed the Node and AMD checks). I'd like to see a fixed version so we don't have to hack up the code every time we want to upgrade.

I'm not real familiar with require.js. Surely, this problem is a common one, right?

@kgust
Copy link
Author

kgust commented May 27, 2014

I'm not from Sweden, but my great-grandfather was. He settled in ND (which is where I was born). I've been in Chicago almost 25 years.

@kgust
Copy link
Author

kgust commented May 27, 2014

Sorry, ND = North Dakota.

@marcuswestin
Copy link
Owner

I'm not sure how common the problem is - not many people report having this
issue. Are you guys a 3rd party plugin? If yes, that would explain why it's
a problem to you more than most people.

I'm ears all open for a proper solution. I ask every time someone brings up
an issue like this, but all I get are one-off fixes that solve their
particular problem :)

On Tue, May 27, 2014 at 5:54 PM, Kevin Gustavson
[email protected]:

Sorry, ND = North Dakota.


Reply to this email directly or view it on GitHubhttps://github.com//issues/96#issuecomment-44295512
.

@kgust
Copy link
Author

kgust commented May 27, 2014

I guess you could call us third-party. At least in the sense that the page is already established and the require.js stuff is handled by someone else.

The reason that I thought this would be common was because there should be lots of pages where additional amd-aware libraries are loaded into a require.js managed site.

@marcuswestin
Copy link
Owner

Do you have an example of a library that does it right in all cases? I'm
really looking for a model that works.

On Tue, May 27, 2014 at 6:01 PM, Kevin Gustavson
[email protected]:

I guess you could call us third-party. At least in the sense that the page
is already established and the require.js stuff is handled by someone else.

The reason that I thought this would be common was because there should be
lots of pages where additional amd-aware libraries are loaded into a
require.js managed site.


Reply to this email directly or view it on GitHubhttps://github.com//issues/96#issuecomment-44296452
.

@kgust
Copy link
Author

kgust commented May 27, 2014

Unfortunately, no. As I said, I’m not very familiar with require.js.

I may end up facing a similar issue in the near future. I have a jQuery plugin that should be made AMD compatible.

@normanzb
Copy link

normanzb commented Sep 9, 2014

@kgust I think ideally you should wrap every module brought in by your component carefully to make it "self-contained" and "no global pollution", so it doesn't affect the other's require.js context or conflict with existing global name spacing.

for doing that, you can use something like this https://github.com/normanzb/amdshim to build your project.

Simply say, it is lightweight version of AMD APIs that provide an internal implementation of require() and define(), so that while benefiting from using require js, your component will stay self-contained and green.

Alternatively, if you don't mind polluting the other's web page, you can always define store as a global object at https://github.com/marcuswestin/store.js/blob/master/store.js#L165, but i strongly against this approach as it may still conflict with target page, what if the webpage is using store.js and they are using a different version?

@marcuswestin
Copy link
Owner

This may very well have been solved by 7c65e0a. @kgust, can you please verify and/or close?

Thanks for the patience!

@kgust
Copy link
Author

kgust commented Mar 11, 2015

I can't verify currently with the problematic site, but this should fix it.

@kgust kgust closed this as completed Mar 11, 2015
@marcuswestin
Copy link
Owner

Thanks Kevin

On Wed, Mar 11, 2015 at 2:17 PM, Kevin Gustavson [email protected]
wrote:

Closed #96 #96.


Reply to this email directly or view it on GitHub
#96 (comment).

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

3 participants