2013-06-01 4 views
0

저는 AppJS/NodeJS와 edge를 사용하여 기본적인 데모 애플리케이션을 만들었습니다.AppJs 및 nodejs 내의 외부 모듈 사용

기본적으로 외부 모듈을 참조하기 만하면 app.js 구성 파일의 관련 부분을 확인합니다.

....... 
window.on('ready', function(){ 
    console.log("Window Ready"); 
    window.process = process; 
    window.module = module; 
    window.dns = require('native-dns'); 
    window.edge = require('edge'); 
    window.fs = require('fs'); 
    window.frame.openDevTools(); 
    .......... 

그리고 heres는 주요 index.html을 페이지의 관련 자바 스크립트 부분 :

....... 
    function myFunction1() 
    { 
     var question = dns.Question({ 
      name: 'www.google.com', 
      type: 'A' 
     }); 

    var req = dns.Request({ 
     question: question, 
     server: { address: '8.8.8.8', port: 53, type: 'udp' }, 
     timeout: 1000 
    }); 

    req.on('timeout', function() { 
     console.log('Timeout in making request'); 
    }); 

    req.on('message', function (err, answer) { 
     answer.answer.forEach(function (a) { 
      console.log(a.address); 
     }); 
    }); 

    req.on('end', function() { 
     console.log('Finished processing request'); 
    }); 

    req.send(); 

} 

function myFunction2() 
    { 
    var helloWorld = edge.func('async (input) => { return ".NET Welcomes " + input.ToString(); }'); 

    helloWorld('JavaScript', function (error, result) { 
     if (error) throw error; 
     console.log(result); 
    }); 
} 

.......... 

내가 다른 nodejs 모듈 (DNS 조회)를 사용 myFunction1()를 호출하면이 완벽하게 작동합니다. 그러나 가장자리를 사용하는 myFunction2()를 호출하면 다음 오류가 발생합니다!

Uncaught TypeError: Property 'func' of object [object Object] is not a function 

나는 이것에 몇 시간을 보냈다. 왜 그런 일이 일어나지 않았는가!

답변

0

동일한 myFunction2 코드를 app.js, 즉 nodejs에서 실행 해 보았습니까? 어쩌면 func 함수가 가장자리 객체에 존재하지 않을 수도 있습니다. 문서를 확인하여 아마도 같은 것을해야 할 필요가 있습니다. window.edge = require ('edge').

또는 비슷한 순간에 내가 가지고 있다고 생각하는 물건을 잡아 당길 수 있습니다. console.log (window.edge)를 실행하여 출력 내용을 볼 수도 있습니다 (노드 및 브라우저에서 dev 도구 (F12)를 실행하는 경우 모두).

/simon

+0

감사합니다. Simon - 저것 좀 봐주세요! – user1513388