npm运行构建时出现问题- BABEL_OUTPUT不是可识别命令

mlnl4t2r  于 2023-03-18  发布在  Babel
关注(0)|答案(1)|浏览(272)

当我运行npm run build时,我得到这个错误:

> plugin-test@0.1.0 build-esm
> BABEL_OUTPUT=esm babel src --extensions ".ts,.tsx,.js,.jsx" --copy-files --out-dir esm

"BABEL_OUTPUT" не является внутренней или внешней
командой, исполняемой программой или пакетным файлом.
(translated from Russian: "BABEL_OUTPUT" is not a recognised internal or external command)

我已经安装了babel-core,babel-cli和babel-node,但仍然收到此错误。我看到在我的包中执行的命令。json:
"build-esm": "BABEL_OUTPUT=esm babel src --extensions \".ts,.tsx,.js,.jsx\" --copy-files --out-dir esm",
有什么想法如何解决这个问题?

w8f9ii69

w8f9ii691#

我观察到这个错误只发生在windows中,不发生在ubuntu中。要解决这个错误,您可以修改package.josn文件的脚本标记。

"scripts": {
    "build": "npm run build-cjs && npm run build-esm && npm run ts-types",
    "build-cjs": "babel src --extensions \".ts,.tsx,.js,.jsx\" --copy-files --out-dir lib",
    "build-clean": "npm run clean && npm run build",
    "build-esm": "BABEL_OUTPUT=esm babel src --extensions \".ts,.tsx,.js,.jsx\" --copy-files --out-dir esm",
    "dev": "BABEL_OUTPUT=esm babel src --extensions \".ts,.tsx,.js,.jsx\" --watch --copy-files --out-dir esm",
    "prebuild": "rimraf {lib,esm,tsconfig.tsbuildinfo}",
    "postbuild": "npm run test",
    "ts-types": "tsc --build",
    "test": "jest"
  }

"scripts": {
    "build": "npm run build-cjs && npm run build-esm && npm run ts-types",
    "build-cjs": "babel src --extensions \".ts,.tsx,.js,.jsx\" --copy-files --out-dir lib",
    "build-clean": "npm run clean && npm run build",
    "build-esm": "set BABEL_OUTPUT=esm babel src --extensions \".ts,.tsx,.js,.jsx\" --copy-files --out-dir esm",
    "dev": "set BABEL_OUTPUT=esm babel src --extensions \".ts,.tsx,.js,.jsx\" --watch --copy-files --out-dir esm",
    "prebuild": "rimraf {lib,esm,tsconfig.tsbuildinfo}",
    "postbuild": "npm run test",
    "ts-types": "tsc --build",
    "test": "jest"
  }

更换零件

"build-esm": "set BABEL_OUTPUT=esm babel src --extensions \".ts,.tsx,.js,.jsx\" --copy-files --out-dir esm",
"dev": "set BABEL_OUTPUT=esm babel src --extensions \".ts,.tsx,.js,.jsx\" --watch --copy-files --out-dir esm",

然后尝试建立它会工作。

相关问题