简体   繁体   English

babel 命令在终端中运行时转换但运行脚本以错误结束

[英]babel command converts when run in terminal but running the script ends in error

I've been trying to get babel core and cli to convert modern JavaScript from index.js into bundle.js.我一直在尝试让 babel 核心和 cli 将现代 JavaScript 从 index.js 转换为 bundle.js。

here is my simple package.json这是我的简单 package.json

{
    "name": "chapter19",
    "version": "1.0.0",
    "description": "",
    "main": "index.js",
    "scripts": {
        "babel": "./node_modules/.bin/babel ./src/index.js -w -o ./dist/assets/bundle.js"
    },
    "author": "",
    "license": "ISC",
    "devDependencies": {
        "@babel/cli": "^7.16.7",
        "@babel/core": "^7.16.7",
        "@babel/preset-env": "^7.16.7",
        "babel-loader": "^8.2.3"
    }
}

now when I run node_modules/.bin/babel./src/index.js -w -o./dist/assets/bundle.js in terminal, it works fine but when I try to run "npm run babel" in terminal, I get the following errors.现在当我在终端中运行node_modules/.bin/babel./src/index.js -w -o./dist/assets/bundle.js时,它工作正常但是当我尝试在终端中运行“npm run babel”时,我收到以下错误。 so far here is what I've tried:到目前为止,这是我尝试过的:

"babel": "node_modules/.bin/babel src/index.js -w -o dist/assets/bundle.js"

result: 'node_modules' is not recognized as an internal or external command, operable program or batch file.结果:“node_modules”未被识别为内部或外部命令、可运行程序或批处理文件。

"babel": "./node_modules/.bin/babel src/index.js -w -o dist/assets/bundle.js"

result:'.'结果:'。' is not recognized as an internal or external command, operable program or batch file.不被识别为内部或外部命令、可运行程序或批处理文件。

I have also read this issue, which is basically:我也读过这个问题,基本上是:

"babel": "node ./node_modules/.bin/babel src/index.js -w -o dist/assets/bundle.js"

OR或者

"babel": "node ./node_modules/.bin/babel ./src/index.js -w -o ./dist/assets/bundle.js"

and I get the following error:我收到以下错误:

SyntaxError: missing ) after argument list
    at Object.compileFunction (node:vm:352:18)
    at wrapSafe (node:internal/modules/cjs/loader:1031:15)
    at Module._compile (node:internal/modules/cjs/loader:1065:27)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
    at node:internal/main/run_main_module:17:47

here is my folder structure (in case if its needed)这是我的文件夹结构(如果需要)

在此处输入图像描述

For those who are interested in resolving this issue, in Windows you can use the following:对于那些有兴趣解决此问题的人,在 Windows 中,您可以使用以下内容:

"scripts": {
    "babel": ".\\node_modules\\.bin\\babel src\\index.js -w -o dist\\assets\\bundle.js"
},

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

相关问题 在Babel上运行npm运行脚本错误 - npm run script error on Babel 无法通过npm脚本运行babel“babel:command not found” - Unable to run babel via npm script “babel: command not found” 运行babel-node时出错 - Error when running babel-node 尝试运行 npm 运行开发命令时遇到错误 - Running into error when trying to run npm run dev command 当我运行“npm run prod”命令时,终端显示“error:03000086:digital envelope routines::initialization error” - Terminal is showing "error:03000086:digital envelope routines::initialization error" when I run "npm run prod" command 在 bash 脚本中运行 AWS 服务会在尝试运行第二个命令时产生错误,我做错了什么吗? - Running AWS services in bash script creates an error when trying to run the second command, am I doing something wrong? node.js 在运行 babel 脚本时找不到模块 - node.js cannot find module when running babel script 运行 Ubuntu 20.04 时,在 VSCode 终端中使用启动命令会出现“权限被拒绝”错误 - When running Ubuntu 20.04, using start command in the VSCode terminal gives "Permission Denied" error Webpack + Babel 不在命令脚本上编译? - Webpack + Babel not compiling on command script? 无法在CLI上运行babel命令 - Unable to run babel command on CLI
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM