json npm无法识别虚拟环境

shstlldc  于 2022-11-26  发布在  其他
关注(0)|答案(3)|浏览(162)

我正在做一个react应用程序,后端是flask,我在this article指南中,所以在本文中他添加了一个自定义的npm脚本来启动flask应用程序。我做了完全相同的事情,并做了npm run start-api,但我得到了以下错误-

> weather-app@0.1.0 start-api C:\Users\Kakshipth\Documents\coding\webdev\weather-app
> cd api && venv/bin/flask run --no-debugger

'venv' is not recognized as an internal or external command,
operable program or batch file.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! weather-app@0.1.0 start-api: `cd api && venv/bin/flask run --no-debugger`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the weather-app@0.1.0 start-api 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\Kakshipth\AppData\Roaming\npm-cache\_logs\2020-10-31T05_01_09_393Z-debug.log

是的,我仔细检查了我的虚拟环境的名称是否正确,它是正确的。
这是我的package.json文件,我在其中指定了脚本-

{
  "name": "weather-app",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^4.2.4",
    "@testing-library/react": "^9.5.0",
    "@testing-library/user-event": "^7.2.1",
    "materialize-css": "^1.0.0",
    "react": "^16.14.0",
    "react-dom": "^16.14.0",
    "react-scripts": "3.4.3",
    "venv": "^1.0.1"
  },
  "scripts": {
    "start": "react-scripts start",
    "start-api": "cd api && venv/bin/flask run --no-debugger",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "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"
    ],
    "proxy": "http://localhost:5000"
  }
}

任何帮助都是感激不尽的,谢谢

9o685dep

9o685dep1#

为了在虚拟环境中运行,您需要首先对虚拟环境进行activate
尝试在激活虚拟环境后执行npm脚本

$ source venv/bin/activate
$ npm run start-api
nnsrf1az

nnsrf1az2#

您正在Windows上运行,它无法识别您在package.json文件中给定的路径,请将"scripts"编辑为:

"start-api": "cd api && venv\\bin\\flask run --no-debugger",

然后尝试激活虚拟环境并运行npm脚本。

$ source venv/bin/activate
$ npm run start-api
4nkexdtk

4nkexdtk3#

我也遵循了同样的例子,答案在这里:Integration of React framework and Flask framework
您需要同时运行这两个命令。
我与yarn同时安装,然后根据concurrently文档更新了package.json中的命令,以使用这两个命令,例如。

"start": "concurrently \"command1 arg\" \"command2 arg\""

相关问题