【问题标题】:dotenv: command not found in nestjs projectdotenv:在 nestjs 项目中找不到命令
【发布时间】:2021-12-15 08:17:50
【问题描述】:

我正在开发一个 NestJS 项目。我正在尝试启动项目,但在终端中出现错误:dotenv: command not found。我检查了 packages.json 并且可以看到安装了 dotenv。此外,我尝试使用 Yarn 安装 dotenv,但仍然遇到同样的错误。

package.json 中的依赖项:

"dependencies": {
    "@nestjs/common": "^8.1.1",
    "@nestjs/config": "1.0.2",
    "@nestjs/core": "^8.1.1",
    "@nestjs/jwt": "^8.0.0",
    "@nestjs/passport": "^8.0.1",
    "@nestjs/platform-express": "^8.1.1",
    "@nestjs/swagger": "^5.1.2",
    "@prisma/client": "3.3.0",
    "bcrypt": "^5.0.1",
    "class-transformer": "^0.4.0",
    "class-validator": "^0.13.1",
->  "dotenv": "^10.0.0",
    "express-rate-limit": "^5.5.0",
    "helmet": "^4.6.0",
    "nanoid": "^3.1.30",
    "nodemailer": "^6.7.0",
    "passport": "^0.5.0",
    "passport-jwt": "^4.0.0",
    "reflect-metadata": "^0.1.12",
    "request-ip": "^2.1.3",
    "rimraf": "^3.0.2",
    "rxjs": "^7.4.0",
    "swagger-ui-express": "^4.1.4"

},

我正在使用的启动脚本:

"start:dev": "dotenv -e env/local.env -- nest start --watch",

【问题讨论】:

    标签: javascript node.js npm yarnpkg dotenv


    【解决方案1】:

    我找到了解决方案,它可能对其他人有所帮助。要在终端中运行 dotenv 命令,我们需要 dotenv-cli。使用yarn add dotenv-cli 安装 dotenv-cli 解决了我的问题。

    【讨论】:

    • 我将dotenv-cli 安装为 dev 依赖,但找不到 dotenv 命令,只能作为 prod 依赖,为什么?
    猜你喜欢
    • 2016-09-09
    • 1970-01-01
    • 2022-11-12
    • 2021-12-31
    • 2022-11-12
    • 2020-06-02
    • 2022-01-18
    • 2013-11-20
    • 2016-09-17
    相关资源
    最近更新 更多