简体   繁体   中英

Nx Angular - no such file or directory, open 'd:\...\TheApp\Source\Angular.Apps/apps/app-client/src/environments/environment.prod.ts'

I've spent some time working on a PowerShell project to automate some builds of my C# and Angular apps which are based on @Nrwl NX monorepos. Prior to this everything worked fine, but when I try a simple:

nx build --baseHref=/apps/admin/ --deployUrl=/apps/admin/ --watch 

I now get the error

ENOENT: "no such file or directory, open 'd:\Projects\TheApp\Source\Angular.Apps/apps/the-client/src/environments/environment.prod.ts'" 

Problem : I assume it's looking for environment.prod.ts because the replaceFile section, but since I'm building in local dev I would have though it shouldn't do the replacement at all.
Also: It's looking for the APP-CLIENT environment file even though I'm building the APP-ADMIN app.

Some points that could have caused issues during my build automation project:

  1. I renamed all the app configurations in workspace.json. So for example "production" became "production-client1" which makes use of the environment.prod.client1.ts file during replacement

    "fileReplacements": [
    {
    "replace": "apps/app-admin/src/environments/environment.ts",
    "with": "apps/app-admin/src/environments/environment.prod.orgb.ts" }
    ],

  2. In 1) above I mentioned the file environment.prod.client1.ts which is originally the environment.prod.ts file. Since the error mentions that it can't find this file it could be that the problem is either here or that I should changed some additional configuration to make this work?

Final note: My powershell cmdlet calls the following command:

nx build portfolio-client --deleteOutputPath=false --baseHref=/apps/client/ --deployUrl=/apps/client/ --configuration=staging-client-client1 

And this works like a charm as does the admin app and the variations for each client. It's only during dev builds that I'm experiencing these issues.

Edit 1:
I created dummy files for environment.prod.ts and environment.staging.ts in the two "application" type projects that I have and this resolved the problem. These files are blank though so not sure why building for Dev/local isn't just working off the environment.ts file

I found the answer in the comments of the following GitHub reported issue: "Error: ENOENT: no such file or directory" for deleted file #3370

What it came down to was that the Nrwl file file-hasher.js makes use of git hashes and since I had not committed those changes it was looking for an old filename. I resolved it by staging and committing all my changes on the current branch.

Looking further this seems to be a bug that was later fixed in Nx 10.0.2 and up, which we haven't upgraded to yet.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM