Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8212459
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T10:45:53+00:00 2026-06-07T10:45:53+00:00

I have a question that I can’t seem to find an answer to. I’m

  • 0

I have a question that I can’t seem to find an answer to. I’m currently building a library for consumption and I want to use requirejs to make it more modular. I have the following project structure…

- example
    - scripts
        - otter
            - libs
                - signals
                    signals.js
            - modules
                subModule1.js
                subModule2.js
            otter.js
    index.htm

- src
    - libs (copied to example folder at build time)
        - signals
            signals.js
    - modules
        subModule1.coffee
        subModule2.coffee
    - otter.coffee

What I want to do is be able to require the signals.js file, and any of my modules, from any of my other files without requiring a path to be setup in require, or without me having to know about how the project is setup at development time.

For example, what I’ve attempted to do in my otter.coffee file is this:

define ['/libs/signals/signals'], (signals) ->
    # I've also tried './libs/signals/signals' and 'libs/signals/signals'

This doesn’t seem to work as require can’t find the signals.js file.

How can I get requirejs to load modules relative to the current file? I’ve read that I can ask for require as a dependency and that the path for that require will be set to the path of the file, but that doesn’t seem to work either. It throws a not loaded yet error i:e –

define (require) ->
    signals = require './libs/signals/signals'

Any ideas how I can accomplish this? Do I need to change the structure of my library? Do I have to force a specific structure? Do I ask those who use it to include certain paths in their require config?

Many thanks in advance!

EDIT –

I’ve noticed that if I alias my library inside my main.js file for require, the require (through require or define) of signals doesn’t work (keep getting 404 not found). However, if I don’t alias my library everything works fine..

For example, if my require main.js file has..

...
paths: {
    'otter': 'scripts/otter/otter'
}
...

then the require of signals fails. However, if I don’t have the path and I require otter through it’s direct path, the require of signal works. I’m requiring signal like this in otter.js …

define (require) ->
    signals = require './libs/signals/signals'

It this a bug with require.js?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T10:45:57+00:00Added an answer on June 7, 2026 at 10:45 am

    RequireJS uses two functions to do its job: define() and require().

    My understanding is that define() lists dependencies and only loads modules; loading dependencies that are not modules (those who not use define()) is done with require().

    Because only modules can load modules, there have to be someone else to load the first module. In your case, to use signals.js in otter.js the first has to be a module and the second has to use require(). I guess that a require() is always needed before any define() uses.

    otter.js:

    require.config({
      paths: {
        'signals': 'libs/signals/signals',
        'module1': 'modules/subModule1'
      }
    });
    
    require(['signals'], function(signals) {
      signals.initialize();
    });
    

    signals.js:

    define(['module1'], function(module) {
      return {
        initialize: function() {
          module.doStuff();
        }
      }
    });
    

    subModule1.js:

    define([], function() {
      return {
        doStuff: function() {
          console.log('hello world');
        }
      }
    });
    

    ps. Loading modules relative to the current file do not seems to be allowed: a baseUrl property is used to configure every modules paths in requirejs.config().

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Have a question that I can't seem to find an answer for. I am
I have a quick question that I can't seem to find online. I am
I have a question about Beanshell that I can't find an answer to anywhere.
I have a question that I can't quite find the answer to... If you
I have a question that can I use AS400ConnectionPool in Spring if then pls
I was hoping if anyone can answer a fundamental question that I have regarding
I have a basic question that I can't seem to resolve using Google (Or
Hi I have a question that can I use such a this code: if
I'm frustratingly new to xslt and have a question that I just can't seem
Hi I have a question that how can we use Horner data structure for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.