Best practice for secrets, like using environmental variables?


Which version of CLI / Runtime / Webpack you are using, it must be latest, in earlier versions we had this issue.


Thanks. Seems like that was the issue. I am still not able to get $ tns bundle ios... to work, but I think that is a separate provisioning profile issue. With $ tns run ios... it now works.

It works after I went through the upgrade instructions here . I used these commands in my terminal to update everything:

npm install -g nativescript  

tns update

tns platform remove ios
tns platform add ios

npm install tns-core-modules@latest --save

npm i nativescript-dev-webpack@latest --save-dev  
 ./node_modules/.bin/update-ns-webpack --deps --configs

npm i nativescript-angular@latest --save
npm i

For some reason I had to rerun the following commands to get webpack to work:

npm i nativescript-dev-webpack --save-dev  
 ./node_modules/.bin/update-ns-webpack --deps --configs

And here is the working code:


new webpack.DefinePlugin({
        "global.TNS_WEBPACK": "true",
         "process": undefined,
        "myGlobal.MySecret": JSON.stringify(env.first_property)


import {OnInit...

declare let myGlobal: any


export class MainPageComponent implements OnInit {

ngOnInit(): void {
  console.log(myGlobal.MySecret) // prints "yaySecret" with the run command I have below

Run command:

$ tns run ios --bundle --env.uglify --env.aot --env.first_property="yaySecret"