【问题标题】:NODE_ENV was unexpected at this time errorNODE_ENV 此时出现意外错误
【发布时间】:2019-11-10 14:24:55
【问题描述】:

我在 youtube 上关注本教程,因为我正在尝试学习 node.js / express。

我在 package.json 文件中更改了以下内容,以便能够使用 nodemon。

package.json

  "scripts": {
    "start": "if [[ $NODE_ENV == 'production' ]]; then node ./bin/www; else nodemon ./bin/www; fi"
  },

但是,当我在 cmd 提示符下运行以下命令时,出现错误。

set DEBUG=myapp:* & npm start

以下错误:

$NODE_ENV was unexpected at this time.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! myapp@0.0.0 start: `if [[ $NODE_ENV == 'production' ]]; then node ./bin/www; else nodemon ./bin/www; fi`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the myapp@0.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
  • 我已经尝试更新所有 npm 模块。 -我试过删除 package-lock.json 并重新安装所有东西。

我好像想不通。

【问题讨论】:

  • 您的 shell 需要能够解释该语法。这不是安装问题,而是 shell 语法错误。就像我在 Ubuntu 上尝试使用 rmdir /S /Q www 一样,它会失败

标签: javascript node.js json express


【解决方案1】:

我尝试全局安装 nodemon 并且成功了。

npm install -g nodemon

"scripts": {
  "start": "node ./bin/www"
}

并使用nodemon 启动应用程序

【讨论】:

    【解决方案2】:

    我得到了同样的错误,但我把它改成了:

    "scripts": {
       "start": "node ./bin/www",
       "dev": "nodemon ./bin/www"
     },
       
    

    它适用于我我正在为 npm 使用“yarn dev”和“npm run dev”。

    【讨论】:

      【解决方案3】:

      “脚本”:{ “开始”:“节点 ./bin/www” }

      现在运行 nodemon 或 npm start

      【讨论】:

        【解决方案4】:

        如果你只想运行 nodemon 你可以这样做

        "start" : "nodemon ./bin/www"
        

        仅此而已。你们都可以走了

        【讨论】:

          猜你喜欢
          • 2013-07-06
          • 1970-01-01
          • 1970-01-01
          • 2017-11-22
          • 2021-06-24
          • 2013-03-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多