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

Be smarter about setting up stringjs #317

Closed
aldeed opened this issue Mar 28, 2015 · 6 comments
Closed

Be smarter about setting up stringjs #317

aldeed opened this issue Mar 28, 2015 · 6 comments

Comments

@aldeed
Copy link
Collaborator

aldeed commented Mar 28, 2015

If requirejs is used, like if raix:famono pkg is added to the app, then window.S won't be set so S will be undefined. This might be a good time to pull out the pieces of stringjs that we're using and eliminate that dependency altogether.

@bompi88
Copy link

bompi88 commented May 29, 2015

Is there a way around this, without rewriting Simple Schema? I tried to wrap my meteor app as a desktop app, with the framework Electron. And for this I use requirejs. I get errors like:

"Exception in template helper: TypeError: S is not a function
    at inflectedLabel (http://localhost:3000/packages/aldeed_simple-schema.js?e210968641793751997ffe233af33b53af8566e4:2136:10)
    at SimpleSchema.getDefinition (http://localhost:3000/packages/aldeed_simple-schema.js?e210968641793751997ffe233af33b53af8566e4:2688:30)
    at SimpleSchema.label (http://localhost:3000/packages/aldeed_simple-schema.js?e210968641793751997ffe233af33b53af8566e4:2741:18)
    at Object.autoFormFieldLabelText (http://localhost:3000/packages/aldeed_autoform.js?b2b90d28d5cc29be68358bb3c8bb8a337992a7dd:1309:23)
    at http://localhost:3000/packages/blaze.js?a5c324925e5f6e800a4c618d71caf2848b53bf51:2880:16
    at http://localhost:3000/packages/blaze.js?a5c324925e5f6e800a4c618d71caf2848b53bf51:1651:16
    at http://localhost:3000/packages/blaze.js?a5c324925e5f6e800a4c618d71caf2848b53bf51:2928:66
    at Function.Template._withTemplateInstanceFunc (http://localhost:3000/packages/blaze.js?a5c324925e5f6e800a4c618d71caf2848b53bf51:3476:12)
    at http://localhost:3000/packages/blaze.js?a5c324925e5f6e800a4c618d71caf2848b53bf51:2927:27
    at Spacebars.call (http://localhost:3000/packages/spacebars.js?7bafbe05ec09b6bbb6a3b276537e4995ab298a2f:172:18)", source: http://localhost:3000/packages/meteor.js?43b7958c1598803e94014f27f5f622b0bddc0aaf (888)

@bompi88
Copy link

bompi88 commented May 29, 2015

I solved it for my purpose by forking the Simple Schema repository, and by rewriting the following code snippet:

if (Meteor.isClient) {
  S = window.S;
}

So it looks like the code snippet below:

if (Meteor.isClient) {
  if(window && window.require) {
    S = window.require("string");
  } else {
    S = window.S;
  }
}

It tests if requirejs is available on the window property, if so use it to define S, else do the same thing as before.

@orlaqp
Copy link

orlaqp commented Sep 10, 2015

I am also having this issue and on top of that if I go to the console and I run:

window.require("string");

I get undefined back ... is that the only solution I can apply here? By the way my issue with Simple-Schema is only when reference another schema, ex:

var a = new SimpleSchema({
   name: {
       type: String
   }
});

var b = new SimpleSchema({
   someNames: {
       type: [a]
   }
});

Any suggestion here?

@marbemac
Copy link

For those running into this issue with Electron, you can add S to the window object inside of a pre-script, instead of forking and customizing the simple schema package. So...

Inside of your electron root:

npm install string --save

Inside of a js file, in your electron root, like browser-setup.js

S = require('string');

Then, in your main.js electron file (or wherever your entry point is), when you create your browser window:

// Create the browser window.
// Here, we have it load the browser-setup.js pre-script, 
// which runs in the context of the meteor app, before any of the meteor app js is loaded.
// This is also how you make native node modules available to your meteor app.
mainWindow = new BrowserWindow({
    'web-preferences': {
        preload: Path.resolve(Path.join(__dirname, 'browser-setup.js')),
    }
})

// Load the meteor app in the browser window
mainWindow.loadUrl('http://localhost:3000');

@marcodejongh
Copy link
Contributor

Anyone still facing this problem, can check out the code in the PR #480 as workaround till the PR is merged.

@aldeed aldeed closed this as completed in d0b1e63 Nov 12, 2015
@aldeed
Copy link
Collaborator Author

aldeed commented Nov 12, 2015

I merged @marcodejongh's PR and will release it soon after I have fixed a few other things.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants