无法使用@ babel/preset-env运行node.js文件 [英] Unable to run a node.js file with @babel/preset-env
问题描述
我正在尝试运行一个简单的node.js文件,该文件需要@ babel/preset-env预设.运行js文件的那一刻,我收到一条消息
I'm trying to run a simple node.js file which needs the @babel/preset-env preset. The moment I run the js file, I get a message saying
需要Babel"7.0.0-0",但已加载"6.26.3"
Requires Babel "7.0.0-0" but was loaded with "6.26.3"
要复制该问题,请在新文件夹中尝试以下操作: 1.运行以下命令
To replicate the issue, please try the following in a new folder: 1. Run the following commands
npm init
npm install @babel/register
npm install @babel/core@^7.2.2
npm install @babel/preset-env
- 使用以下内容创建.babelrc文件
{
"presets": ["@babel/preset-env"],
"plugins": []
}
- 使用以下内容创建示例emp.jsx
import React from "react";
class CommentBox extends React.Component {}
- 使用以下内容创建parse.js文件
require('babel-register')({presets: ['env', 'react']});
let Emp = require('./emp.jsx');
现在通过运行来运行parse.js文件
Now run the parse.js file by running
node parse.js
您应该看到上面提到的错误.我已经尝试修复很长时间了.请帮忙.
You should see the error mentioned above. I have been trying to fix with for a long time now. Please help.
非常感谢
推荐答案
发现了问题. .babelrc文件包含对@ babel/preset-env的引用.删除它,并编译js文件就可以了.
Found the problem. The .babelrc file that contained a reference to @babel/preset-env. Removed it and the js file compiled just fine.
这篇关于无法使用@ babel/preset-env运行node.js文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!