npm:启动脚本失败

时间:2020-03-18 19:32:17

标签: node.js npm

我正在Windows 10上使用Node.js(v12.16.1)开发一个简单的后端项目。

我的package.json文件包含以下命令:

"scripts": {
    "start": "NODE_ENV=production node --experimental-modules --require dotenv/config server.mjs dotenv_config_path=config/config.env",
    ...
}

当我输入npm run start时,我得到

> NODE_ENV=production node --experimental-modules --require dotenv/config server.mjs dotenv_config_path=config/config.env

'NODE_ENV' is not recognized as an internal or external command,
operable program or batch file.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! devcamper-api@1.0.0 start: `NODE_ENV=production node --experimental-modules --require dotenv/config server.mjs dotenv_config_path=config/config.env`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the devcamper-api@1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

为什么会发生这种故障?

1 个答案:

答案 0 :(得分:0)

Windows无法理解这种设置环境变量的方式。 请使用跨环境软件包:https://www.npmjs.com/package/cross-env

npm install --save-dev cross-env

,然后在您的脚本中:

"cross-env NODE_ENV=production ... "