Angular-cli: Permission error on second build when nomodule polyfill is included

Created on 30 Aug 2019  Β·  25Comments  Β·  Source: angular/angular-cli

🐞 Bug report

Command (mark with an x)


- [ ] new
- [x] build
- [ ] serve
- [ ] test
- [ ] e2e
- [ ] generate
- [ ] add
- [ ] update
- [ ] lint
- [ ] xi18n
- [ ] run
- [ ] config
- [ ] help
- [ ] version
- [ ] doc

Is this a regression?

I'm not sure. This is the first time I've seen it, but I recently upgraded to Angular 8.

Description


I reproducibly get a permission error, seen below, in a clean, brand new angular project, when browserslist specifies browsers that require nomodule polyfill.

πŸ”¬ Minimal Reproduction

  1. ng new test
  2. In the new project, add to browserslist: ios_saf >= 10
  3. ng build --prod
  4. ng build --prod (again)

πŸ”₯ Exception or Error


chunk {0} runtime-es2015.24b02acc1f369d9b9f37.js (runtime) 2.83 kB [entry] [rendered]
chunk {1} main-es2015.7c221f45d48105c2ba9d.js (main) 251 kB [initial] [rendered]
chunk {2} polyfills-es2015.fd917e7c3ed57f282ee5.js (polyfills) 64.3 kB [initial] [rendered]
chunk {3} polyfills-es5-es2015.3aa54d3e5134f5b5b842.js (polyfills-es5) 223 kB [initial] [rendered]
chunk {4} styles.3ff695c00d717f2d2a11.css (styles) 0 bytes [initial] [rendered]
chunk {polyfills-nomodule-es5} polyfills-nomodule-es5.b79bfebc521ac1ea1602.js (polyfills-nomodule-es5) 372 bytes [entry] [rendered]
Date: 2019-08-30T21:28:19.886Z - Hash: c40b7c3c8a049ad41deb - Time: 12280ms
Generating ES5 bundles for differential loading...
An unhandled exception occurred: EACCES: permission denied, copyfile '/Users/karp/Documents/git/outputhashing2/node_modules/.cache/angular-build-dl/content-v2/sha512/f3/26/48b77841506560fd29c0954a8fe431f253a24b4306fd7399aaec8a09d0dcc974a357856c0b742e8e40a0ac34f406ebc3b58955f738ea327fc8e1819cd7a3' -> '/Users/karp/Documents/git/outputhashing2/dist/outputhashing2/polyfills-nomodule-es5.b79bfebc521ac1ea1602.js'
See "/private/var/folders/pf/z4z5f17x7jb0n0m44bmkhyw00000gn/T/ng-7tYGDL/angular-errors.log" for further details.

🌍 Your Environment


Angular CLI: 8.3.2
Node: 10.16.0
OS: darwin x64
Angular: 8.2.4
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.803.2
@angular-devkit/build-angular     0.803.2
@angular-devkit/build-optimizer   0.803.2
@angular-devkit/build-webpack     0.803.2
@angular-devkit/core              8.3.2
@angular-devkit/schematics        8.3.2
@angular/cli                      8.3.2
@ngtools/webpack                  8.3.2
@schematics/angular               8.3.2
@schematics/update                0.803.2
rxjs                              6.4.0
typescript                        3.5.3
webpack                           4.39.2

Anything else relevant?
Nuking node_module (and presumably just the cache dir within) and reinstalling fixes the issue for one build.
Sorry to put this out there on a Friday afternoon!

devkibuild-angular high regression bufix

Most helpful comment

Some other users also seem to experience An unhandled exception occurred: EEXIST: file already exists, copyfile

All 25 comments

Some other users also seem to experience An unhandled exception occurred: EEXIST: file already exists, copyfile

According to the other issue, this may happen even without the change to browserslist. I thought the problem popped up when I made that change, but I could easily have missed that.

Yeah, the issue is not related to the browserslist file per see, it's related to a change in 8.3.

I had the same problem and after removing node_modules and npm install it works as it should be.

I get this error:

An unhandled exception occurred: EACCES: permission denied, copyfile '/home/christian/projects/test/node_modules/.cache/angular-build-dl/content-v2/sha512/a9/aa/c96f81fde2bc334f1b8e2b015df4c8a584a2c6ba48340a9f4c61cb9d5d3462764f4d023cac89edbdfe7197a1afb211a7d5b2166196daeef021af40d4fcc7' -> '/home/christian/projects/test/dist/test/assets/js/bootstrap.min.js'

The problem is fixed by PR #15512, but many of the generated files are now world-writable (see below). Deploying these files could be less secure than before.

I know nothing about the internal workings of an angular build, but it looks like files are cached and later copied to 'dist'. The files in the cache already have their mode reset to 0o444. Wouldn't it be possible to save the file there with the correct permissions?

If not I would advocate for a less open mode of 0o664 or 0o644.

Nonetheless, thank you for looking into this issue.

Before #15512

-rw-rw-r-- 1 christian christian  15K Sep  4 10:31 3rdpartylicenses.txt
drwxrwxr-x 4 christian christian   27 Sep  4 10:31 assets
-rw-rw-r-- 1 christian christian  948 Sep  4 10:31 favicon.ico
-r--r--r-- 1 christian christian 253K Sep  4 10:31 main-es2015.0840fbfe83afb92a9535.js
-r--r--r-- 1 christian christian 288K Sep  4 10:31 main-es5.0840fbfe83afb92a9535.js
-r--r--r-- 1 christian christian  37K Sep  4 10:31 polyfills-es2015.fd917e7c3ed57f282ee5.js
-r--r--r-- 1 christian christian 117K Sep  4 10:31 polyfills-es5.f9fad3ad3c84e6dbdd72.js
-r--r--r-- 1 christian christian 1.5K Sep  4 10:31 runtime-es2015.24b02acc1f369d9b9f37.js
-r--r--r-- 1 christian christian 1.5K Sep  4 10:31 runtime-es5.24b02acc1f369d9b9f37.js
-rw-rw-r-- 1 christian christian    0 Sep  4 10:31 styles.09e2c710755c8867a460.css

After #15512

-rw-rw-r-- 1 christian christian  15K Sep  4 10:36 3rdpartylicenses.txt
drwxrwxr-x 4 christian christian   27 Sep  4 10:36 assets
-rw-rw-r-- 1 christian christian  948 Sep  4 10:36 favicon.ico
-rw-rw-r-- 1 christian christian  924 Sep  4 10:36 index.html
-rw-rw-rw- 1 christian christian 253K Sep  4 10:36 main-es2015.0840fbfe83afb92a9535.js
-rw-rw-rw- 1 christian christian 288K Sep  4 10:36 main-es5.0840fbfe83afb92a9535.js
-rw-rw-rw- 1 christian christian  37K Sep  4 10:36 polyfills-es2015.fd917e7c3ed57f282ee5.js
-rw-rw-rw- 1 christian christian 117K Sep  4 10:36 polyfills-es5.f9fad3ad3c84e6dbdd72.js
-rw-rw-rw- 1 christian christian 1.5K Sep  4 10:36 runtime-es2015.24b02acc1f369d9b9f37.js
-rw-rw-rw- 1 christian christian 1.5K Sep  4 10:36 runtime-es5.24b02acc1f369d9b9f37.js
-rw-rw-r-- 1 christian christian    0 Sep  4 10:36 styles.09e2c710755c8867a460.css

@chtisgit Assets being processed as described in that error was a bug that was fixed in the 8.3.1. Please ensure that the CLI is at the latest version (8.3.2) and the @angular-devkit/build-angular is as well (0.803.2).

As to the permissions, does the project have the deleteOutputPath set to false?

Can someone help me on this, I am getting this error 'EEXIST: file already exists, mkdir'
when I execute ng build --prodwith --output-path flag specified.

I have:

  • angular/cli version 7.3.8
  • angular-devkit/build-angular 0.13.9
  • node 10.15.3 (npm 6.4.1)

Same problem with:

  • "@angular-devkit/build-angular": "^0.803.3",
  • "@angular/cli": "~8.3.3",

In my case I just added the "deleteOutputPath": true inside the build->options of angular.json to make-sure the output path is deleted before the build, now its working fine!

In my case I just added the "deleteOutputPath": true inside the build->options of angular.json to make-sure the output path is deleted before the build, now its working fine!

This not works for me, do you do any other thing?

@pagimaxx I had the same issue, but it was resolved after running npm ci. Give that a shot

@pagimaxx I had the same issue, but it was resolved after running npm ci. Give that a shot

I'm not entirely sure how this aids the ng build, as AFAIK that command tells npm to clean the node_modules folder before installing packages πŸ€·β€β™€οΈ

Just sounds like a coincidence to me.

@jjz4689 my assumption is that some data in the npm cache was causing the issue. Worked for me πŸ™ƒ

@jjz4689 my assumption is that some data in the npm cache was causing the issue. Worked for me πŸ™ƒ

@JoeOsterfeld Ah yes, makes sense - maybe the devkit for build was getting cached, hence the failure even after updating in package.json πŸ€”

EDIT: npm ci seemed to do the trick on my CI build on a darwin x64 system. Cheers, Joe πŸŽ‰

Im still having this issue with SSR.

$ npm ci
$ npm install
$ npm run build:ssr

works once, but when you do another:

$ npm run build:ssr

Im still getting

An unhandled exception occurred: EEXIST: file already exists, copyfile '/Users/username/repos/My-App/node_modules/.cache/angular-build-dl/content-v2/sha512/78/34/68fa9b30c624f8e9421d00abdf638ff1e8e9144a07899d53cd54afd6d73aea97cd25dae86452c8cc4adb93fcb65ee92fff16b5d2434dec6d1e97419d95bc' -> '/Users/username/repos/My-App/dist/mybiz/runtime-es2015.c472732038d5f504ebc8.js'
See "/private/var/folders/wh/s6w5z3hs5cb463mgk6z96n480000gn/T/ng-8L28Rj/angular-errors.log" for further details.

@borriej I don't think running npm install is necessary as you're already running npm ci before it, which installs packages as part of its process.

In my case, I just swapped out my npm install for npm ci in my CI build and it worked OK for me.

But, I can't be totally sure if this is what's causing the issue for you, and in my case, I'm not running SSR.

im having this on my local machine using

    "@angular/cli": "~8.3.3",
    "@angular-devkit/build-angular": "~0.803.3",

even running a single

$ ng build --prod

gives the error

An unhandled exception occurred: EEXIST: file already exists, copyfile '/Users/username/repos/My-App/node_modules/.cache/angular-build-dl/content-v2/sha512/78/34/68fa9b30c624f8e9421d00abdf638ff1e8e9144a07899d53cd54afd6d73aea97cd25dae86452c8cc4adb93fcb65ee92fff16b5d2434dec6d1e97419d95bc' -> '/Users/username/repos/My-App/dist/mybiz/runtime-es2015.c472732038d5f504ebc8.js'
See "/private/var/folders/wh/s6w5z3hs5cb463mgk6z96n480000gn/T/ng-8L28Rj/angular-errors.log" for further details.

caused by Differential Loading :(, because the error comes after

Generating ES5 bundles for differential loading...

browserlist is empty and tsconfig looks like

{
    "compileOnSave": false,
    "compilerOptions": {
        "baseUrl": "./",
    "downlevelIteration": false,
    "importHelpers": false,
        "outDir": "./dist/out-tsc",
        "sourceMap": true,
        "declaration": false,
        "module": "esnext",
        "moduleResolution": "node",
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "allowJs": true,
        "target": "es2015",
        "typeRoots": [
            "node_modules/@types"
        ],
        "lib": [
            "es2017",
            "dom"
        ],
        "paths": {
            "@app/*": ["./src/app/*"],
            "@env/*": ["./src/environments/*"],
            "@routes/*": ["./routes/*"]
        }
    },
    "include": [
        "src/**/*",
        "node_modules/ts-money/**/*"
    ]
}

I'm no expert, but I'd suggest, if you are still having this problem with the latest Angular CLI, completely deleting node_modules, and re-installing. Then, if you are _still_ having the problem, report this as a new related issue (with a link to this one), since this issue is closed, and was fixed, at least for the case reported originally.

If anyone is encountering the EEXIST error on MacOS, please try a node version of 10.16.0 or greater. There is a known issue with copying files on earlier versions of node for MacOS.

@clydin Thank you very much for pointing me in the right direction, indeed my problems went away by updating. Also my concern about the file mode setting is obsolete with commit 0cb10d6029f59842b2f6e0a791d78b43ea1a7460.

wow thanks guys! I solved it...

I was using nvm with the latest version v11.12.0...

solution was to use the stable Node!

nvm install v10.16.3
nvm use v10.16.3

I was getting the same issue running "npm run electron-build" which of course does an "ng build --prod". I was using node 11.6.0. I installed n from npm and got node 10.16.3, 11.15.0 and 12.10.0...

When I used node version 10x or 12x everything was fine, but with node version 11x the problem just will not go away.

https://www.surrealcms.com/blog/how-to-upgrade-or-downgrade-nodejs-using-npm.html

I had the same problem and after removing node_modules and npm install it works as it should be.

this helped me as well - deleting and re-installing node_modules

Apparently, error mentioned a node_modules/.cache directory where the file mentioned in error is located.
I just delete node_modules/.cache directory, launch ng build --prod again and it works!

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

_This action has been performed automatically by a bot._

Was this page helpful?
0 / 5 - 0 ratings

Related issues

hareeshav picture hareeshav  Β·  3Comments

sysmat picture sysmat  Β·  3Comments

MateenKadwaikar picture MateenKadwaikar  Β·  3Comments

IngvarKofoed picture IngvarKofoed  Β·  3Comments

purushottamjha picture purushottamjha  Β·  3Comments