我正在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! [email protected] 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 [email protected] start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
为什么会发生这种故障?
Windows不了解这种设置环境变量的方式。请使用跨环境软件包:https://www.npmjs.com/package/cross-env
npm install --save-dev cross-env
然后在您的脚本中:
"cross-env NODE_ENV=production ... "
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句