2016년 8월 2일 화요일

[Node.js] TypeError: require(...) is not a function 해결방법

'use strict';

module.exports = function(param){
    // something to handle
    require('./otherModule)(param);
});

위와 같은 코드 형태에서 TypeError: require(...) is not a function 에러가 났었다.
아래처럼 고치니 잘 작동했다.

module.exports = function(param){
    // something to handle
    require('./otherModule)(param);
});

혹시나싶어서 'use strict'를 지웠는데, 그것이 먹혔다.
이유를 알고싶어 검색하다가 아래와 같은 글을 찾았다.
Aliencube Community :: 자바스크립트에서 strict mode를 사용해야 하는 이유

엄격한 컨텍스트에서는 require('...')() 을 제한하나보다. 혹은 "상대적으로 안전하지 않은 액션"이였거나..


댓글 없음:

게시글 목록