简体   繁体   English

Node js抛出关于严格模式的错误,尽管将babel 6预设es2015与包含严格模式一起使用

[英]Node js throw error about strict mode although using babel 6 preset es2015 with contains strict mode

node js throw this error uncaughtException: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode although I'm using babel 6 es2015 present that suppose to add use strict . 节点js抛出此错误uncaughtException: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode尽管我正在使用babel 6 es2015表示应该添加use strict ,但uncaughtException: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode

I have .babelrc file exist and this is how I instantiate babel: 我有.babelrc文件存在,这是我实例化babel的方法:

require("babel-core").transform("code", {
    retainLines: true
}); 

Furthermore, when I use babel CLI to see the output files they have use strict 此外,当我使用babel CLI查看输出文件时,它们use strict

Am I missing something? 我想念什么吗?

** EDIT: Is it possible node js doesn't use the output of babel? **编辑:是否有可能节点js不使用babel的输出?

I found the answer. 我找到了答案。

I changed 我变了

require("babel-core").transform("code", {
    retainLines: true
});

to

require("babel-core/register");

and configured all the options in the .babelrc file 并配置.babelrc文件中的所有选项

What weird is that this (what I initially did) appear in babel documentation ( https://babeljs.io/docs/setup/#installation ) 奇怪的是,这(我最初所做的)出现在babel文档( https://babeljs.io/docs/setup/#installation )中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM