虽然使用babel 6预设es2015包含严格模式,但Node js抛出严格模式错误

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

本文关键字:模式 js Node 错误 babel 预设 es2015 包含严      更新时间:2023-09-26

node js抛出这个错误uncaughtException: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode,虽然我使用babel 6 es2015 present,假设添加use strict

我有.babelrc文件存在,这就是我如何实例化babel:

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

此外,当我使用babel CLI查看输出文件时,它们具有use strict

我错过了什么吗?

* *编辑:是否有可能节点js不使用巴别塔的输出?

我找到了答案。

I changed

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

require("babel-core/register");

并在.babelrc文件

中配置了所有选项

奇怪的是,这(我最初所做的)出现在babel文档(https://babeljs.io/docs/setup/#installation)