0

The following code works:

define(["./my/dependency"], function (myDep) {
    return awesomeness
    // Everything is fine :)
}

It would be very nice, due to restrictions in the environment I'm working in, to define dependencies earlier in an array but this doesn't work:

deps = ["./my/dependency"]

define(deps, function (myDep) {
    return abandonAllHope
    // Everything is terrible :(
})

I'm new to Javascript/requireJS/nodeJS and working to alter an existing nodeJS project. The website fails to load major elements when I try the second option. I'm not sure how to bugfix this issue and can't understand why only the second option fails.

3
  • How are you adding the dependencies to the array? Commented May 15, 2018 at 1:17
  • Right now just as shown, with an implicitly created array of strings. (deps = ["./my/dependencies"]) I was trying to do something fancier earlier, but then boiled the error down to this. Commented May 15, 2018 at 1:26
  • That doesn't seem to be the error. There is probably something else wrong somewhere. Commented May 15, 2018 at 1:35

1 Answer 1

0

I can see two problems:

  • missing var keyword
  • you are defining global variable deps which might be overwriting something

Please try this one, this uses anonymous function which is calling itself instance:

(function () {
    var deps = ["./my/dependency"];

    define(deps, function (myDep) {
        return abandonAllHope
        // Everything is terrible :(
    });
}());
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.