[英]Unable to run a node.js file with @babel/preset-env
I'm trying to run a simple node.js file which needs the @babel/preset-env preset.我正在尝试运行一个需要 @babel/preset-env 预设的简单 node.js 文件。 The moment I run the js file, I get a message saying
我运行 js 文件的那一刻,我收到一条消息说
Requires Babel “7.0.0-0” but was loaded with “6.26.3”需要 Babel “7.0.0-0” 但加载了 “6.26.3”
To replicate the issue, please try the following in a new folder: 1. Run the following commands要复制该问题,请在新文件夹中尝试以下操作: 1. 运行以下命令
npm init
npm install @babel/register
npm install @babel/core@^7.2.2
npm install @babel/preset-env
{ "presets": ["@babel/preset-env"], "plugins": [] }
import React from "react"; class CommentBox extends React.Component {}
require('babel-register')({presets: ['env', 'react']}); let Emp = require('./emp.jsx');
Now run the parse.js file by running现在通过运行运行 parse.js 文件
node parse.js
You should see the error mentioned above.您应该会看到上面提到的错误。 I have been trying to fix with for a long time now.
我已经尝试修复很长时间了。 Please help.
请帮忙。
Many Thanks非常感谢
followed your instructions and using @babel/register instead with this package.json run with no issues按照您的指示并使用 @babel/register 代替这个 package.json 运行没有问题
tasted on
node : v8.11.2
yarn : 1.12.3
paese.json paese.json
require('@babel/register')({});
let Emp = require('./emp.jsx');
console.log(Emp)
packge.json包.json
{
"name": "sof",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"devDependencies": {
"@babel/core": "^7.2.2",
"@babel/preset-env": "^7.2.3",
"@babel/register": "^7.0.0"
},
"dependencies": {
"react": "^16.7.0"
}
}
Found the problem.发现问题了。 The .babelrc file that contained a reference to @babel/preset-env.
包含对@babel/preset-env 的引用的 .babelrc 文件。 Removed it and the js file compiled just fine.
删除它并且js文件编译得很好。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.