【问题标题】:error 'env' is not recognized as an internal or external command?错误“env”不被识别为内部或外部命令?
【发布时间】:2021-09-16 14:08:38
【问题描述】:

我是 node.js 的新手,我已经安装了 node.js 并使用推荐 npm -v 检查了它的工作正常,我尝试测试它从

构建开源项目
github https://github.com/quran/quran.com-frontend

运行项目的命令是

  npm run dev

我收到了这个错误

    C:\Users\Acer\Desktop\quran.com-frontend-master\quran.com-frontend-master>npm run dev

    > quran@1.0.0 dev C:\Users\Acer\Desktop\quran.com-frontend-master\quran.com-frontend-master
    > env NODE_PATH='./src' PORT=8000 UV_THREADPOOL_SIZE=100 node ./webpack/webpack-dev-server.js & env NODE_PATH='./src' PORT=8000 node ./bin/server.js

    'env' is not recognized as an internal or external command,
    operable program or batch file.
    'env' is not recognized as an internal or external command,
    operable program or batch file.

    npm ERR! Windows_NT 10.0.14393
    npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "dev"
    npm ERR! node v6.9.2
    npm ERR! npm  v3.10.9
    npm ERR! code ELIFECYCLE
    npm ERR! quran@1.0.0 dev: `env NODE_PATH='./src' PORT=8000 UV_THREADPOOL_SIZE=100 node ./webpack/webpack-dev-server.js & env NODE_PATH='./src' PORT=8000 node ./bin/server.js`
    npm ERR! Exit status 1
    npm ERR!
    npm ERR! Failed at the quran@1.0.0 dev script 'env NODE_PATH='./src' PORT=8000 UV_THREADPOOL_SIZE=100 node ./webpack/webpack-dev-server.js & env NODE_PATH='./src' PORT=8000 node ./bin/server.js'.
    npm ERR! Make sure you have the latest version of node.js and npm installed.
    npm ERR! If you do, this is most likely a problem with the quran package,
    npm ERR! not with npm itself.
    npm ERR! Tell the author that this fails on your system:
    npm ERR!     env NODE_PATH='./src' PORT=8000 UV_THREADPOOL_SIZE=100 node ./webpack/webpack-dev-server.js & env NODE_PATH='./src' PORT=8000 node ./bin/server.js
    npm ERR! You can get information on how to open an issue for this project with:
    npm ERR!     npm bugs quran
    npm ERR! Or if that isn't available, you can get their info via:
    npm ERR!     npm owner ls quran
    npm ERR! There is likely additional logging output above.
    npm WARN Local package.json exists, but node_modules missing, did you mean to install?

    npm ERR! Please include the following file with any support request:
    npm ERR!     C:\Users\Acer\Desktop\quran.com-frontend-master\quran.com-frontend-master\npm-debug.log

【问题讨论】:

    标签: node.js command-line


    【解决方案1】:

    在 windows 上,'env' 命令默认不被识别;在那里我找到了两个选择:

    1. 改用另一个命令,例如:
        set VARIABLE_NAME=custom name
    
    1. 安装 cygwin 并将其安装路径设置为 windows 环境变量。安装后,您可以从命令行使用:
        env VARIABLE_NAME=custom name
    

    这里是 cygwin 安装详细信息的链接:https://www.howtogeek.com/howto/41382/how-to-use-linux-commands-in-windows-with-cygwin/

    【讨论】:

      【解决方案2】:

      您可以在 Windows 中使用 linux 终端(如 git bash)。如果你使用这个,你可以在 npm 上配置脚本 shell:

      // for git bash
      $ npm config set script-shell "C:\Program Files\git\bin\bash.exe" 
      // or
      $ npm config set script-shell "C:\Program Files\git\bin\sh.exe" 
      

      对于任何其他:

      $ npm config set script-shell <Your favorite shell>
      

      【讨论】:

        【解决方案3】:

        Nodejsnpm 是不同的。 npm(node package manager) 用于安装nodejs的依赖。服务器所需的依赖项将在 package.json 文件中列出。 看起来 env 模块有问题。尝试使用 npm 安装dotenv module

        npm install dotenv --save
        

        在安装这个模块之前,使用命令更新你的 npm

        npm update
        

        【讨论】:

        • i 错误已删除但我无法运行该项目
        • @dacijilole3030 嘿,你能告诉我在我的系统上运行它的步骤吗?尽管没有更多错误,但仍然无法正常工作
        • 嗨@dacijilole3030,很抱歉延迟回复。确保遵循项目中列出的自述文件中的说明。使用 npm run dev 命令运行节点服务器并尝试访问 url localhost:8001 以检查服务器是否正在运行。
        【解决方案4】:

        我在安装安全帽时遇到了这个问题。 这个问题基本上是 npm 试图运行 bash 命令 您可以直接运行以下命令来更改脚本的默认 shell

        $ npm config set script-shell "C:\Program Files\git\bin\bash.exe"
        

        【讨论】:

          猜你喜欢
          • 2019-06-13
          • 2018-07-28
          • 2017-12-15
          • 2018-11-01
          • 2022-11-11
          • 2021-09-15
          • 2021-02-08
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多