【问题标题】:Issue with use of env-cmd in react application在反应应用程序中使用 env-cmd 的问题
【发布时间】:2020-04-26 18:29:06
【问题描述】:

系统:

操作系统:Windows 10 IDE:Visual Studio 代码

我正在开发一个包含以下 package.json 的 react 应用程序

{
  "name": "test-app",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "animakit-expander": "^2.1.4",
    "animakit-rotator": "^2.1.3",
    "axios": "^0.19.0",
    "circular-json": "^0.5.9",
    "env-cmd": "^10.0.1",
    "file-saver": "^2.0.2",
    "jquery": "^3.4.1",
    "jsonwebtoken": "^8.5.1",
    "jszip": "^3.2.2",
    "mdbreact": "^4.22.1",
    "rc-queue-anim": "^1.8.2",
    "react": "^16.12.0",
    "react-dom": "^16.12.0",
    "react-if-elseif-else-render": "^1.0.2",
    "react-lazylog": "^4.4.1",
    "react-loading-overlay": "^1.0.1",
    "react-native-orientation-loading-overlay": "^0.1.6",
    "react-overlay-loader": "0.0.3",
    "react-overlay-loading": "^1.0.3",
    "react-scripts": "3.2.0",
    "react-scrollbar": "^0.5.6",
    "react-transition-group": "^4.3.0",
    "reactjs-popup": "^1.5.0",
    "reactstrap": "^8.1.1",
    "velocity-react": "^1.4.3"
  },
  "scripts": {
    "start": "env-cmd -f ./.env.dev react-scripts start",
    "start-dev": "env-cmd -f ./.env.dev react-scripts start",
    "test": "react-scripts test --coverage",
    "eject": "react-scripts eject",
    "build": "react-scripts build",
    "start1": "react-scripts start"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}

当我在终端中运行命令时,npm run start,我面临以下问题:

> test-app@0.1.0 start C:\dev\test-app
> env-cmd -f ./.env.dev react-scripts start

'-f' is not recognized as an internal or external command,
operable program or batch file.
spawn  -f ENOENT
internal/process/per_thread.js:189
      throw errnoException(err, 'kill');
      ^

Error: kill ENOSYS
    at process.kill (internal/process/per_thread.js:189:13)
    at TermSignals._terminateProcess (C:\dev\test-app\node_modules\env-cmd\dist\signal-termination.js:47:28)
    at process.terminateSpawnedProcessFuncHandlers.<computed> (C:\dev\test-app\node_modules\env-cmd\dist\signal-termination.js:20:30)
    at Object.onceWrapper (events.js:300:26)
    at process.emit (events.js:210:5)
    at process.exit (internal/process/per_thread.js:158:15)
    at TermSignals._uncaughtExceptionHandler (C:\dev\test-app\node_modules\env-cmd\dist\signal-termination.js:68:17)
    at process.<anonymous> (C:\dev\test-app\node_modules\env-cmd\dist\signal-termination.js:40:53)
    at process.emit (events.js:210:5)
    at process._fatalException (internal/process/execution.js:150:25) {
  errno: 'ENOSYS',
  code: 'ENOSYS',
  syscall: 'kill'
}
npm ERR! code ELIFECYCLE
npm ERR! errno 7
npm ERR! test-app@0.1.0 start: `env-cmd -f ./.env.dev react-scripts start`
npm ERR! Exit status 7
npm ERR!
npm ERR! Failed at the test-app@0.1.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\me\AppData\Roaming\npm-cache\_logs\2020-01-09T07_15_50_457Z-debug.log

当我直接在任何终端中运行 env-cmd -f ./.env.dev react-scripts start 时,我的应用程序运行良好。

请提供您的建议。

【问题讨论】:

    标签: reactjs npm package.json


    【解决方案1】:

    您可以尝试将 .env.dev 文件放在与 package.json 相同的文件夹级别并尝试通过将其更改为来运行脚本

    env-cmd -f .env.dev react-scripts start

    【讨论】:

    • 是的,我试过了,但问题是“'-f' 不被识别为内部或外部命令,”
    • 我认为这可能是文件路径的问题。您是否尝试过创建像“.env-cmdrc”这样的默认文件并将其放在项目的根目录中。有关示例,请参阅alligator.io/nodejs/take-command-with-env-cmd 的 RC 文件部分。在这种方法中,您不需要使用“-f”。
    猜你喜欢
    • 2017-10-05
    • 2019-08-20
    • 1970-01-01
    • 1970-01-01
    • 2021-02-17
    • 2022-07-06
    • 1970-01-01
    • 2021-12-19
    • 2022-07-06
    相关资源
    最近更新 更多