[javascript] –harmony_modules 옵션을 사용하여 노드 v6.0.0에서 ES2015 “가져 오기”가 작동하지 않음
노드 v6.0.0을 사용하고 있으며 ES2016 (ES6)을 사용하고 싶었습니다. 그러나 “가져 오기”구문이 작동하지 않는다는 것을 깨달았습니다. ES2015에서 모듈 코드를 작성하기 위해 “가져 오기”가 기본이 아닙니까? --harmony_modules
옵션으로 노드를 실행하려고했지만 “가져 오기”에 대해 동일한 오류가 발생했습니다. 여기에 코드가 있습니다.
“가져 오기”가없는 작업 코드 :
'use strict';
let sum = 0;
class Number {
addNumber(num1, num2) {
return num1 + num2;
}
}
let numberObj = new Number();
sum = numberObj.addNumber(1,2);
console.log("sum of two number 1 and 2 "+ sum);
“가져 오기”로 작동하지 않는 코드 :
server.js
'use strict';
import Number from "./Number";
let sum = 0;
let numberObj = new Number();
sum = numberObj.addNumber(1,2);
console.log("sum of two number 1 and 2 "+ sum);
Number.js
'use strict';
export default class Number {
addNumber(num1, num2) {
return num1 + num2;
}
}
또한 http://node.green/ 을 확인하여 지원되는 es6를 확인했지만 –harmony_modules 옵션과 함께 작동하지 않는 이유를 이해할 수 없었습니다. 도와주세요.
답변
아직 구현되지 않았습니다.
Node 6.0.0은 대부분의 ES6 기능이 완료된 V8 버전을 사용합니다. 불행히도 모듈은 완성 된 기능 중 하나가 아닙니다.
node --v8-options | grep harmony
진행중인 조화 플래그가 완전히 구현되지 않았으며 일반적으로 작동하지 않습니다.
–es_staging (테스트 할만한 하모니 기능 활성화 ( 내부 전용 ))
–harmony (완성 된 모든 하모니 기능
활성화 ) –harmony_shipping (제공된 모든 하모니 기능
활성화 ) –harmony_object_observe ( “harmony Object.observe”활성화 ( in progress ))
–harmony_modules ( “harmony modules”활성화 ( 진행 중 ))
–harmony_function_sent ( “harmony function.sent”활성화 ( 진행 중 ))
–harmony_sharedarraybuffer ( “harmony sharedarraybuffer 활성화 ( 진행 중 )))
–harmony_simd ( “harmony simd”활성화 ( 진행 중 ))
–harmony_do_expressions ( “harmony do-expressions”
활성화 ( 진행 중 ))
–harmony_iterator_close ( “조화 반복기 종료”활성화 ( 진행 중 ))
–harmony_tailcalls ( “하모니 테일 호출”활성화 ( 진행 중 ))
–harmony_object_values_entries ( “harmony Object.values / Object.entries”
활성화 ( 진행 중 ))
–harmony_object_own_property_descriptors ( “harmony Object.getOwnPropertyDescriptors ()”
활성화 ( 진행 중 ))
–harmony_regexp_property ( “하모니 유니 코드 정규 표현식 속성 클래스”활성화 ( 진행 중 )) )
–harmony_function_name ( “하모니 함수 이름 추론 “)
–harmony_regexp_lookbehind ( “harmony regexp lookbehind”
활성화 ) –harmony_species ( “harmony Symbol.species”
활성화 ) –harmony_instanceof ( “harmony instanceof support”
활성화 ) –harmony_default_parameters ( “harmony default parameters”
활성화) “harmony destructuring assignment”)
–harmony_destructuring_bind ( “harmony destructuring bind”
활성화 ) –harmony_tostring ( “harmony toString”
활성화 ) –harmony_regexps ( “harmony 정규 표현식 확장”
활성화 ) –harmony_unicode_regexps ( “harmony unicode regexps”활성화)
–harmony_sloppy ( “조잡한 모드에서 조화 기능 활성화”)
–harmony_sloppy_let ( “조잡한 모드에서 하모니 렛”활성화)
–harmony_sloppy_function ( “조잡한 기능 블록 범위 지정”
활성화 ) –harmony_proxies ( “조화 프록시”
활성화 ) –harmony_reflect ( “harmony Reflect API”
활성화 ) –harmony_regexp_subclass ( “조화 정규식 하위 분류”활성화)
답변
@Paulpro의 답변에 대한 댓글이어야하지만 댓글을 게시 할 충분한 담당자가 없습니다.
들어 윈도우 사용자에 해당하는 명령은 다음과 같습니다
node --v8-options | findstr harmony
답변
모듈이 구현 될 때까지 Babel “transpiler” 를 사용하여 코드를 실행할 수 있습니다.
npm install --save babel-cli babel-preset-node6
./node_modules/.bin/babel-node --presets node6 ./your_script.js
참조 https://www.npmjs.com/package/babel-preset-node6 및 https://babeljs.io/docs/usage/cli/
단점 : 여기에는 추가 컴파일 시간과 같은 다양한 단점이 있으며 이는 중요 할 수 있으며 이제 디버깅을위한 소스 맵이 필요합니다. 그냥 말해.