nx build does not replace environment file in any variation
See original GitHub issueI have the following configuration in my workspace.json
for my NodeJS project:
"configurations": {
"production": {
"optimization": true,
"extractLicenses": true,
"inspect": false,
"fileReplacements": [
{
"replace": "apps/api/src/environments/environment.ts",
"with": "apps/api/src/environments/environment.prod.ts"
}
]
},
"test": {
"optimization": true,
"extractLicenses": true,
"inspect": false,
"fileReplacements": [
{
"replace": "apps/api/src/environments/environment.ts",
"with": "apps/api/src/environments/environment.test.ts"
}
]
}
}
},
The environment files sit in the same hierarchy:
I am unable to find which command will pick up the test
configuration. I have tried multiple things it did not work:
nx build api --test # does not work
NODE_ENV=test nx build api # does not work
NODE_ENV=test nx build api --test # does not work
nx build api -c=test # does not work
nx build api -c test # does not work
nx build api --prod # works for prod env file
Expected Behavior
I should be able to choose between different environment files during the build.
Current Behavior
fileReplacement
does not seem to work for NodeJS project for anything other than prod
.
Steps to Reproduce
In your workspace with one server side project, say api, do the the following:
- Add a new file
environment.test.ts
on the same pattern as the existingenvironment.prod.ts
- In the
workspace.json
under the"api" > "architect" > "buiid" > "configurations"
block, add a new configuration for the “test” environment that looks like the existing “production” configuration, except it has"fileReplacements"
array that looks like this:
{
"replace": "apps/api/src/environments/environment.ts",
"with": "apps/api/src/environments/environment.test.ts"
}
Now try to do a build that picks up and replaces environment.ts with environment.test.ts during the build. It does not seem to be possible.
The commands I tried above did not help me. Here is my nx version.
nx --version
8.9.0
Issue Analytics
- State:
- Created 3 years ago
- Comments:5
Top Results From Across the Web
nwrl nx environment files is not replaced for NodeJS project ...
I should be able to choose between different environment files during the build. Current Behavior. fileReplacement does not seem to work for ...
Read more >Using environment variables in Angular applications - Nx
Using environment variables in Angular applications. By default, Angular only provides the NODE_ENV variable when building the application. You may use ...
Read more >nrwl-nx/community - Gitter
Hey guys, NX environments does not appear to be a suitable replacement for react (non-angular) .env environment variables, as it offers replacement instead ......
Read more >Environment variables - Prisma
An environment variable is a key value pair of string data that is stored on your machine's local environment. Refer to our Environment...
Read more >Configuration | NestJS - A progressive Node.js framework
Since configuration variables change, best practice is to store ... If you don't want to load the .env file, but instead would like...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Apologies. The
--configuration
worked. For some reason when I tried--configuration
yesterday following the documentation (it was documented under Angular project), it worked for the React project but it did not seem to work for NodeJS. It is totally my fault.Thanks for the suggestion.
can you please try
nx build api --configuration=test
?If not, can you please create an example repo showing this problem?