最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

jquery - define is not defined Javascript Node - Stack Overflow

programmeradmin1浏览0评论

I am trying to run a Javascript file with Node to post blog updates to Tumblr.

So far in my main.js file I have this:

// Tumblr Information
var tumblr = require('./vendor/tumblr');
tumblr.request(require('request'));
var Blog;

var jq = require('./vendor/jquery-1.11.1.min');
var reqq = require('./vendor/require');
var inher = require('./vendor/inheritance');

var grammars = require('./tracery/grammar');

But then I receive the following error when I run node main.js

ReferenceError: define is not defined
    at Object.<anonymous> (B:\Documents\Google Drive\Programming\CMPM 147 Tracery\Tumblr Tracery\js\
tracery\grammar.js:6:1)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (B:\Documents\Google Drive\Programming\CMPM 147 Tracery\Tumblr Tracery\js\
main.js:11:16)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)

And here is where the error is being thrown in the grammar.js file:

define(["./modifiers", "./node"], function(universalModifiers, Node) {'use strict';

    // other stuff...
});

I do not think a module is being loaded properly because it is stating the define function isn't defined. I believe this function comes from requireJS but I don't think I am loading it properly. Does anyone have any suggestions on why define might not be defined, or suggestions on how to load the correct module?

Thank you.

I am trying to run a Javascript file with Node to post blog updates to Tumblr.

So far in my main.js file I have this:

// Tumblr Information
var tumblr = require('./vendor/tumblr');
tumblr.request(require('request'));
var Blog;

var jq = require('./vendor/jquery-1.11.1.min');
var reqq = require('./vendor/require');
var inher = require('./vendor/inheritance');

var grammars = require('./tracery/grammar');

But then I receive the following error when I run node main.js

ReferenceError: define is not defined
    at Object.<anonymous> (B:\Documents\Google Drive\Programming\CMPM 147 Tracery\Tumblr Tracery\js\
tracery\grammar.js:6:1)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (B:\Documents\Google Drive\Programming\CMPM 147 Tracery\Tumblr Tracery\js\
main.js:11:16)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)

And here is where the error is being thrown in the grammar.js file:

define(["./modifiers", "./node"], function(universalModifiers, Node) {'use strict';

    // other stuff...
});

I do not think a module is being loaded properly because it is stating the define function isn't defined. I believe this function comes from requireJS but I don't think I am loading it properly. Does anyone have any suggestions on why define might not be defined, or suggestions on how to load the correct module?

Thank you.

Share Improve this question asked Feb 11, 2015 at 9:04 leaflet757leaflet757 1591 gold badge1 silver badge9 bronze badges 3
  • The tumblr part of the code isn't throwing the complaint. I got the tumblr part working find but the line that is causing the issue is the: var grammars = require('./tracery/grammar') – leaflet757 Commented Feb 11, 2015 at 9:12
  • Ah, I see -- the tumblr part of the path led me that way. – T.J. Crowder Commented Feb 11, 2015 at 9:13
  • Why are you using define? That's not how you define a module in Node.js – Ben Fortune Commented Feb 11, 2015 at 9:37
Add a comment  | 

1 Answer 1

Reset to default 17

It looks like you are trying to load a library that is coded according to the AMD (Asynchronous Module Definition) pattern, which Node does not support natively. It is perfectly possible for the author of a library to write such library so that it can be loaded in Node. The users of the library have to extend Node's module loading capabilities to understand AMD in order to load such library.

There are multiple loaders you can use, the one I use is amd-loader. Once installed with npm, you just add

require("amd-loader");

before you load any AMD module.

发布评论

评论列表(0)

  1. 暂无评论