0

I am having trouble to reference requirejs modules with relative path in the code and have them working with grunt-contrib-requirejs. Anyone has any clue on why this might happen?

File Structure:

src
 |
 --config.js
 |
 --js/
    |
    --package
         |
         ---project.js
         |
         ---utils.js

Requirejs config:

require.config({
    paths: {
        jquery: 'vendor/jquery-1.10.1.min'
    },
    shim: {
        jquery: []
    }
});

GruntFile:

  requirejs: {
    compile: {
      options: { 
        name : "./js/package/project",
        baseUrl: "src",
        mainConfigFile: "src/config.js",
        out: "build/js/project-build.js"
      }
    }
 }

In the project.js file, I am referencing a util.js as tryout,

var utilsObject = require('./js/package/utils.js');

When I run grunt requirejs, I get following error:

Error: ENOENT, no such file or directory
>> '{folder}/src/js/package/js/package/utils.js'
>> In module tree:
>>     js/package/project
ttback
  • 2,051
  • 5
  • 27
  • 40

1 Answers1

1

You have set the baseUrl property to 'src' in your configuration. Try to remove it.

I have successfully used jQuery, RequireJS, grunt and grunt-contrib-requirejs to build my plugin. Maybe my setup can give you a hint?

nekman
  • 1,919
  • 2
  • 15
  • 26
  • it had no impact in my case with or without baseUrl, something else must be deciding the base for me. – ttback Nov 21 '13 at 19:08
  • i will read up one your configs and see what i can figure out – ttback Nov 21 '13 at 19:09
  • for some reason even though I managed to compile them into one file, it won't do anything...like nothing really runs, just loaded...something's still off. – ttback Nov 21 '13 at 19:56
  • Do you have a complete example you can show me? Github repository or similar? – nekman Nov 21 '13 at 19:59
  • Yea, i just spent sometime to make a repo that mirrors my current setup and it should be able to illustrate the problem, https://github.com/ttback/requirejs-example. I also made a new question, http://stackoverflow.com/questions/20131718/no-such-file-error-when-using-grunt-requirejs-compile – ttback Nov 21 '13 at 20:59
  • the setup is definitely a bit weird, it's legacy code. I might want to straighten them out with a new requirejs-config.js – ttback Nov 21 '13 at 21:00