jvilk / BrowserFS

BrowserFS is an in-browser filesystem that emulates the Node JS filesystem API and supports storing and retrieving files from various backends.
Other
3.06k stars 216 forks source link

path.join throw error in Service Worker #291

Open jcubic opened 4 years ago

jcubic commented 4 years ago

If you call this path.join('/'. 'file') in service worker it throw exception:

Error: ENOENT: No such file or directory., '/'
Error
    at new ApiError (https://cdn.jsdelivr.net/npm/browserfs@2.x.x/dist/browserfs.js:5430:22)
    at Function.FileError (https://cdn.jsdelivr.net/npm/browserfs@2.x.x/dist/browserfs.js:5455:16)
    at Function.ENOENT (https://cdn.jsdelivr.net/npm/browserfs@2.x.x/dist/browserfs.js:5458:21)
    at https://cdn.jsdelivr.net/npm/browserfs@2.x.x/dist/browserfs.js:13987:37
    at IDBRequest. (https://cdn.jsdelivr.net/npm/browserfs@2.x.x/dist/browserfs.js:14270:17)

it work outside of worker.

james-pre commented 1 year ago

@jcubic Please try with the latest commit. If it still does not work, a PR would be greatly appreciated!

jcubic commented 1 year ago

Will check, is the latest version published to NPM?

james-pre commented 1 year ago

@jcubic I don't believe so. You will need to clone the repo and build from source.

jcubic commented 1 year ago

ok, will see if I will be able to test tomorrow. I'm on a trip but got a laptop with me.

jcubic commented 1 year ago

I'm not able to build the project got error from NodeJS:

Error: error:0308010C:digital envelope routines::unsupported
    at new Hash (node:internal/crypto/hash:71:19)
    at Object.createHash (node:crypto:133:10)
    at module.exports (/home/kuba/projects/jcubic/BrowserFS/node_modules/webpack/lib/util/createHash.js:90:53)
    at NormalModule._initBuildHash (/home/kuba/projects/jcubic/BrowserFS/node_modules/webpack/lib/NormalModule.js:386:16)
    at handleParseError (/home/kuba/projects/jcubic/BrowserFS/node_modules/webpack/lib/NormalModule.js:434:10)
    at /home/kuba/projects/jcubic/BrowserFS/node_modules/webpack/lib/NormalModule.js:466:5
    at /home/kuba/projects/jcubic/BrowserFS/node_modules/webpack/lib/NormalModule.js:327:12
    at /home/kuba/projects/jcubic/BrowserFS/node_modules/loader-runner/lib/LoaderRunner.js:370:3
    at iterateNormalLoaders (/home/kuba/projects/jcubic/BrowserFS/node_modules/loader-runner/lib/LoaderRunner.js:211:10)
    at iterateNormalLoaders (/home/kuba/projects/jcubic/BrowserFS/node_modules/loader-runner/lib/LoaderRunner.js:218:10)
    at /home/kuba/projects/jcubic/BrowserFS/node_modules/loader-runner/lib/LoaderRunner.js:233:3
    at context.callback (/home/kuba/projects/jcubic/BrowserFS/node_modules/loader-runner/lib/LoaderRunner.js:111:13)
    at processMap (/home/kuba/projects/jcubic/BrowserFS/node_modules/source-map-loader/index.js:103:3)
    at /home/kuba/projects/jcubic/BrowserFS/node_modules/source-map-loader/index.js:53:6
    at FSReqCallback.readFileAfterClose [as oncomplete] (node:internal/fs/read_file_context:68:3) {
  opensslErrorStack: [ 'error:03000086:digital envelope routines::initialization error' ],
  library: 'digital envelope routines',
  reason: 'unsupported',
  code: 'ERR_OSSL_EVP_UNSUPPORTED'
}

This seems to be a common NodeJS error but I'm not able to solve it by adding:

export NODE_TLS_REJECT_UNAUTHORIZED=0
james-pre commented 1 year ago

Interesting... I don't believe that error is related to BrowserFS so it is most likely with your machine.

jcubic commented 1 year ago

This is common error with Node and the library failed to handle it properly. sent from Android12.03.2023 2:20 AM "Dr. Vortex" @.***> napisał(a): Interesting... I don't believe that error is related to BrowserFS so it is most likely with your machine.

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you were mentioned.Message ID: @.***>

james-pre commented 1 year ago

@jcubic Have you tried this Stack Overflow answer? It should prevent the SSL error.

jcubic commented 1 year ago

@james-pre thanks it works, I think that I've missed this. But I think that all those errors are problems with the library that doesn't support the latest NodeJS. I have the same with a project I'm maintaining and this is my project's fault that this throws an error and requires disabling security hacks to work.

james-pre commented 1 year ago

@jcubic I'm working on updating all of BrowserFS' various dependencies so it should get fixed soon.

jcubic commented 1 year ago

I've added browserFS build file to my project that uses service worker and I've got a different error:

Error: ENOENT: No such file or directory., '/'

from fs.stat('/test/index.html').

The whole code was working fine. This my setup:

self.addEventListener('fetch', function (event) {
    let path = BrowserFS.BFSRequire('path');
    let fs = new Promise(function(resolve, reject) {
        BrowserFS.configure({ fs: 'IndexedDB', options: {} }, function (err) {
            if (err) {
                reject(err);
            } else {
                resolve(BrowserFS.BFSRequire('fs'));
            }
        });
    });
    event.respondWith(fs.then(function(fs) {
        // ...
    });
});

I'm not sure if the API changed. If I changed the app to also use new BrowserFS that app stops working and throws an error on ls command on the root directory.

What are the breaking changes in 2.0?

james-pre commented 1 year ago

@jcubic

configureAsync (source code) should simplify the code your using. In addition, you no longer need to supply options for IndexedDB (see #352).

As for the error, I'm not entirely sure why it is being thrown. I would suggest you change the code to use configureAsync and change the event listener to use async/await and await the configureAsync call.

I will look into the error more in the mean time (and hopefully fix the ApiError stack)

james-pre commented 1 year ago

@jcubic I just fixed the issues causing the errors above in #355. You should be able to run BFS normally again.

Specifically, this commit fixed multiple errors (see the commit notes)

jcubic commented 1 year ago

Thanks, Will check my app with the latest version.

jcubic commented 1 year ago

The ls command works but when I want to clone the repo. Got an error from this function:

AsyncKeyValueFileSystem.prototype.getDirListing = function getDirListing (tx, p, inode, cb) {
  if (!inode.isDirectory()) {
    cb(ApiError.ENOTDIR(p));
  }
  else {
    tx.get(inode.id, function (e, data) {
      if (noError(e, cb)) {
        try {
          cb(null, JSON.parse(data.toString()));
        }
        catch (e) {
          // Occurs when data is undefined, or corresponds to something other
          // than a directory listing. The latter should never occur unless
          // the file system is corrupted.
          cb(ApiError.ENOENT(p));
        }
      }
    });
  }
};

data is undefined.

Also, I needed to delete the old database because it was not compatible and was throwing errors.

james-pre commented 8 months ago

Closing (stale). If you would like to reopen this issue, please do so by creating a new issue in the relevant repositories of @browser-fs