universal icon indicating copy to clipboard operation
universal copied to clipboard

EEXIST: file already exists | @ngx-cache

Open logan-jobzmall opened this issue 6 years ago • 5 comments

I'm submitting a ... (check one with "x")

[ ] Regression (a behavior that used to work and stopped working in a new release)
[X] Bug report  <!-- Please check the repository for a similar issue or PR before submitting -->
[ ] Support request => <!-- Please check the repository for a similar issue or PR before submitting -->
[ ] Feature request
[ ] Documentation issue or request

Current behavior

When running in production SSR mode, ngx-cache fails on second load. It looks like it tries to create the .cache folder twice, and fails:

Error: EEXIST: file already exists, mkdir '/Users/foo/bar/.cache'
    at Object.fs.mkdirSync (fs.js:874:3)
    at new FsStorageService (/Users/foo/bar/node_modules/@ngx-cache/fs-storage/bundles/ngx-cache-fs-storage.umd.js:131:20)
    at _createClass (/Users/foo/bar/node_modules/@angular/core/bundles/core.umd.js:20740:24)
    at _createProviderInstance (/Users/foo/bar/node_modules/@angular/core/bundles/core.umd.js:20712:30)
    at resolveNgModuleDep (/Users/foo/bar/node_modules/@angular/core/bundles/core.umd.js:20676:25)
    at NgModuleRef_.get (/Users/foo/bar/node_modules/@angular/core/bundles/core.umd.js:21384:20)
    at new FsCacheService (/Users/foo/bar/node_modules/@ngx-cache/platform-server/bundles/ngx-cache-platform-server.umd.js:41:39)
    at _createClass (/Users/foo/bar/node_modules/@angular/core/bundles/core.umd.js:20742:24)
    at _createProviderInstance (/Users/foo/bar/node_modules/@angular/core/bundles/core.umd.js:20712:30)
    at resolveNgModuleDep (/Users/foo/bar/node_modules/@angular/core/bundles/core.umd.js:20676:25)

Expected/desired behavior

The expectation is that the cache services should check to see if the folder exists before trying to recreate it. This error breaks everything and shows in the browser.

Minimal reproduction of the problem with instructions

  1. Checkout the latest ng-seed/universal.
  2. Use npm run start:ssr:prod to start on localhost:4000

logan-jobzmall avatar Jan 15 '19 20:01 logan-jobzmall

has anybody figured out how to fix/workaround this?

shayangz avatar Feb 08 '19 19:02 shayangz

I am facing the same issue, any ideas what is happening?

ERROR { Error: EEXIST: file already exists, mkdir '/Users/myself/projects/tools/universal/.cache'
    at Object.mkdirSync (fs.js:774:3)
    at new FsStorageService (/Users/myself/projects/tools/universal/node_modules/@ngx-cache/fs-storage/bundles/ngx-cache-fs-storage.umd.js:131:20)
    at _createClass (/Users/myself/projects/tools/universal/node_modules/@angular/core/bundles/core.umd.js:21185:24)
    at _createProviderInstance (/Users/myself/projects/tools/universal/node_modules/@angular/core/bundles/core.umd.js:21157:30)
    at resolveNgModuleDep (/Users/myself/projects/tools/universal/node_modules/@angular/core/bundles/core.umd.js:21121:25)
    at NgModuleRef_.get (/Users/myself/projects/tools/universal/node_modules/@angular/core/bundles/core.umd.js:21829:20)
    at new FsCacheService (/Users/myself/projects/tools/universal/node_modules/@ngx-cache/platform-server/bundles/ngx-cache-platform-server.umd.js:41:39)
    at _createClass (/Users/myself/projects/tools/universal/node_modules/@angular/core/bundles/core.umd.js:21187:24)
    at _createProviderInstance (/Users/myself/projects/tools/universal/node_modules/@angular/core/bundles/core.umd.js:21157:30)
    at resolveNgModuleDep (/Users/myself/projects/tools/universal/node_modules/@angular/core/bundles/core.umd.js:21121:25)
  errno: -17,
  syscall: 'mkdir',
  code: 'EEXIST',
  path: '/Users/myself/projects/tools/universal/.cache' }

raviada avatar Feb 09 '19 11:02 raviada

Hi, same problem here, some hint to resolve ?

EEXIST: file already exists, mkdir '/Users/user/work/data-admin-gui/.cache'
    at mkdirSync (fs.js:775:3)
    at new FsStorageService (/Users/user/work/data-admin-gui/dist/server.js:239910:65)
    at _createClass (/Users/user/work/data-admin-gui/dist/server.js:24689:20)
    at _createProviderInstance (/Users/user/work/data-admin-gui/dist/server.js:24661:26)
    at resolveNgModuleDep (/Users/user/work/data-admin-gui/dist/server.js:24625:21)
    at NgModuleRef_.get (/Users/user/work/data-admin-gui/dist/server.js:25333:16)
    at new FsCacheService (/Users/user/work/data-admin-gui/dist/server.js:240075:35)
    at _createClass (/Users/user/work/data-admin-gui/dist/server.js:24691:20)
    at _createProviderInstance (/Users/user/work/data-admin-gui/dist/server.js:24661:26)
    at resolveNgModuleDep (/Users/user/work/data-admin-gui/dist/server.js:24625:21)

meatfly avatar Feb 20 '19 09:02 meatfly

there is bug in XpFsStorageService use if (!stat.isDirectory()) { not if (!stat.hasOwnProperty('isDirectory')) {

workaround can by done by own implementation of storageService https://gist.github.com/meatfly/baff02d8004802a870b77171f0b3f6e0

and than use in app.server.module.ts

   ServerCacheModule.forRoot([
      {
        provide: CACHE,
        useClass: FsCacheService
      },
      {
        provide: STORAGE,
        useClass: XpFsStorageService

meatfly avatar Feb 20 '19 11:02 meatfly

I still have this error

Error: EEXIST: file already exists, mkdir '/usr/src/app/.cache'
    at Object.mkdirSync (fs.js:752:3)
    at new XpFsStorageService (/usr/src/app/dist/server.js:4438:18)
    at _createClass (/usr/src/app/dist/server.js:90200:20)
    at _createProviderInstance (/usr/src/app/dist/server.js:90172:26)
    at resolveNgModuleDep (/usr/src/app/dist/server.js:90136:21)
    at NgModuleRef_../node_modules/@angular/core/fesm5/core.js.NgModuleRef_.get (/usr/src/app/dist/server.js:90844:16)
    at new FsCacheService (/usr/src/app/dist/server.js:123492:35)
    at _createClass (/usr/src/app/dist/server.js:90202:20)
    at _createProviderInstance (/usr/src/app/dist/server.js:90172:26)
    at resolveNgModuleDep (/usr/src/app/dist/server.js:90136:21)

Event with your XpFsStorageService 😕

squelix avatar May 09 '19 12:05 squelix