I am having trouble using the Dojo Toolkit with NodeJS when it comes to requiring a relative standard node.js file:
I have the following directory
node-stuff
start-server.js
source
dojo
app-client
app-common
app-server
lib
http-server.js
routes
index.js
server-config.js
server.js
I use the start-server.js file to bootstrap the dojo toolkit:
dojoConfig = require('./source/app-server/server-config');
require("./source/dojo/dojo.js");
This loads the server configuration file that contains the dojoConfig information
module.exports = {
baseUrl: 'source/',
async: true,
packages: [
{
name: 'dojo',
location: 'dojo'
},
{
name: 'app-server',
location: 'app-server'
},
{
name: 'app-client',
location: 'app-client'
},
{
name: 'app-common',
location: 'app-common'
}
],
deps: [
"source/app-server/server.js"
]
};
Inside of my http-server.js file, I am trying to use the following node require:
define([
"dojo/node!express", //works OK
"dojo/node!path", //works OK
"app-common/roots", //works OK
"dojo/node!../routes/index"] //this last one has the following error message
The error message produced
"C:\Program Files\nodejs\node.exe" start-server.js
module.js:340
throw err;
^
Error: Cannot find module 'source\app-server\routes\index'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at source/dojo/node.js:41:15
at Object.load (source/dojo/node.js:46:6)
at injectPlugin (C:\Users\james_000\RubymineProjects\node-stuff\source\dojo\dojo.js:1321:13)
at C:\Users\james_000\RubymineProjects\node-stuff\source\dojo\dojo.js:1136:6
at forEach (C:\Users\james_000\RubymineProjects\node-stuff\source\dojo\dojo.js:93:6)
at resolvePluginLoadQ (C:\Users\james_000\RubymineProjects\node-stuff\source\dojo\dojo.js:1129:4)
I have tried getting the latest version of node off of the Dojo Github. That changed the error line from
Cannot find module 'source\app-server\routes\index'
to
Cannot find module 'app-server\routes\index'
Is this a bug here, or am I doing something wrong?
I'm wondering if the problem is that the dojo/node! is always coercing the path to be source/app-server/routes/index instead of ./source/app-server/routes/index. If I put the source/app-server/routes folder in the node_modules folder, then it works fine. It doesn't seem to like relative file paths that are not inside of that folder.
EDIT: I tested the above, and it was not correct.
This looks like https://bugs.dojotoolkit.org/ticket/16414#comment:16 which was fixed in Dojo 1.9.1.
EDIT: Also, your baseUrl needs to be an absolute path to the directory.