SharePoint / sp-dev-docs

SharePoint & Viva Connections Developer Documentation
https://docs.microsoft.com/en-us/sharepoint/dev/
Creative Commons Attribution 4.0 International
1.24k stars 1.01k forks source link

Process.env.<variable> are undefined #9571

Open Krugerro opened 6 months ago

Krugerro commented 6 months ago

What type of issue is this?

Question

What SharePoint development model, framework, SDK or API is this about?

💥 SharePoint Framework

Target SharePoint environment

SharePoint Online

What browser(s) / client(s) have you tested

Additional environment details

Issue description

My general aim is to use process.env<variableName> during build locally during development and in devops pipleines during deployment to inject some secrets and passwords. My story about this is pretty same as here (i'm not the author) so I tried every link touching this subject.

What I learned is: in gulpfile none of plugins folowing this is truthy in condition plugin instanceof webpack.DefinePlugin thus new instance of DefinePlugin is pushed which yields to error: image When I manually change plugins array adding in gulpfile (code is simplified) image where getClientEnvironment().stringified is: image My console.log(process.env.SPFX_COMPUTER_VISION_KEY) is undefined in any tsx file.

The only variable defined in DefinePlugin I can access is DEBUG.

I even started to edit node_modules\@microsoft\spfx-heft-plugins\lib\plugins\webpackConfigurationPlugin\WebpackConfigurationGenerator.js where in DefinPlugin argument I added my variables which still gives undefined.

How can I inject my variables to process.env and use them during build?

ghost commented 6 months ago

Thank you for reporting this issue. We will be triaging your incoming issue as soon as possible.