YUI3 + node.js = runInNewContext错误

时间:2011-04-24 00:13:10

标签: node.js yui yui3

我尝试在node.js中运行这个简单的代码:

var YUI = require("yui3");
YUI.use(function(Y) {
console.log('asdasd');
})


但是我收到以下错误:

node.js:178
        throw e; // process.nextTick error, or 'error' event on first tick
        ^
TypeError: Cannot read property 'runInNewContext' of undefined
    at Object.<anonymous> (/usr/local/lib/node/.npm/yui3/0.5.34/package/lib/yui3-yui3.js:7:29)
        at Module._compile (module.js:404:26)
    at Object..js (module.js:410:10)
    at Module.load (module.js:336:31)
    at Function._load (module.js:297:12)
    at require (module.js:348:19)
    at /usr/local/lib/node/.npm/yui3/0.5.34/package/lib/node-yui3.js:2:16
    at Object.use (/usr/local/lib/node/.npm/yui3/0.5.34/package/lib/node-yui3.js:41:15)
    at Object.<anonymous> (/var/www/myDir/libs/nodejs-yui3/yui3_test.js:6:5)
    at Module._compile (module.js:404:26)

我该如何解决这个问题?

[编辑]
我正在使用:node v0.5.0-pre

2 个答案:

答案 0 :(得分:1)

我无法重现这一点。我按照以下步骤操作:

  • 已安装YUI3:

    [BinaryMuse ~/src]: npm install yui3
    [ lots of output ... ]
    npm info build Success: yui3@0.5.34
    npm info build Success: request@1.9.5
    npm info build Success: mime@1.2.1
    npm info build Success: express@2.2.2
    npm info build Success: connect@1.3.0
    npm info build Success: qs@0.1.0
    npm info build Success: htmlparser@1.7.3
    npm info build Success: yui3-core@3.3.0
    npm info build Success: jsdom@0.2.0
    npm ok
    
  • 创建了文件yui.js

    var YUI = require("yui3");
    
    YUI.use(function(Y) {
      console.log('asdasd');
    });
    
  • 跑完程序:

    [BinaryMuse ~/src]: node yui.js 
    asdasd
    

我知道这并没有真正“回答”你的问题,但也许知道它的工作原理将指向正确的方向。祝你好运!

[更新]我在Node v0.4.5上。

答案 1 :(得分:0)

Node.js 0.5.0-pre中引入了此错误,请参阅issue 203中的讨论。 要解决此问题,您可以:

  1. 将节点降级为0.4.7
  2. 或从yui3-yui3.js中删除两个字符串(不知道yui3@0.5.34,但未使用yui3@0.6.0变量),请参阅this ticket