问题描述
即使Lambda函数的仪表板显示NODE_ENV
列为环境变量,但当我运行Node AWS Lambda函数时,process.env.NODE_ENV
仍未定义.
Even though the dashboard for the Lambda function shows me NODE_ENV
listed as an environment variable, process.env.NODE_ENV
is undefined when I run my Node AWS Lambda function.
此代码...
console.log('node process env NODE_ENV:');
console.log(process.env.NODE_ENV);
记录以下内容:
node process env NODE_ENV:
undefined
我想知道这是否是一个角色问题,所以我授予了其角色对AWS Lambda的所有权限,但这无济于事.
I was wondering if it was a role issue, so I gave its role all permissions on AWS Lambda, but it didn't help.
对于它的价值,我使用的是 Claudia bot builder ,运行npm脚本
For what it's worth, I'm using Claudia bot builder, running the npm script
"deploy:production": "claudia update --version production --set-env NODE_ENV=production",
但是就像我说的那样,NODE_ENV
环境显示在该功能的仪表板中的环境变量列表中.
But like I say, the NODE_ENV
environment shows in the list of environment variables in the dashboard for the function.
有什么想法吗?
推荐答案
原来的问题是Webpack压缩了process.env
.
Turns out the problem was that Webpack compressed away process.env
.
我通过使用 babel-plugin-transform-inline-environment-variables ,它会在构建时内联环境变量.
I got around the issue by using babel-plugin-transform-inline-environment-variables, which inlines the environment variables at build-time.
这篇关于未设置AWS Lambda环境变量,在Node中未定义process.env的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!