zen-fs / iso

ZenFS backend for ISO files
https://zen-fs.github.io/iso/
MIT License
2 stars 0 forks source link

Cannot use 'in' operator to search for 'constructor' in undefined #1

Closed murilopereirame closed 3 days ago

murilopereirame commented 5 days ago

When trying to create an ISO backend, it just crashes during import of Iso

import { default as nodeFs } from "fs/promises";
import { configure, fs } from "@zenfs/core";
import { Iso } from "@zenfs/iso";

const loadLibrary = async () => {
  const res = await nodeFs.readFile("ubuntu.iso");
  await configure({
    mounts: {
      "/mnt/iso": { backend: Iso, data: Uint8Array.from(res) },
    },
  });
  const contents = fs.readFileSync("/mnt/iso/install.sh", "utf-8");
  console.log(contents);
};

loadLibrary();
node_modules/@zenfs/iso/node_modules/utilium/dist/struct.js:83
        if ((typeof target != 'object' || typeof target != 'function') && !('constructor' in target)) {
                                                                                          ^

TypeError: Cannot use 'in' operator to search for 'constructor' in undefined
    at file:///home/murilo.pereira/Repositories/tst/node_modules/@zenfs/iso/node_modules/utilium/dist/struct.js:83:91
    at Object._ [as uint16] (file:///home/murilo.pereira/Repositories/tst/node_modules/@zenfs/iso/node_modules/utilium/dist/struct.js:173:28)
    at __esDecorate (file:///home/murilo.pereira/Repositories/tst/node_modules/@zenfs/iso/dist/entries.js:19:40)
    at file:///home/murilo.pereira/Repositories/tst/node_modules/@zenfs/iso/dist/entries.js:80:9
    at file:///home/murilo.pereira/Repositories/tst/node_modules/@zenfs/iso/dist/entries.js:87:7
    at file:///home/murilo.pereira/Repositories/tst/node_modules/@zenfs/iso/dist/entries.js:89:3
    at ModuleJob.run (node:internal/modules/esm/module_job:262:25)
    at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:482:26)
    at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:117:5)

Node.js v22.8.0
james-pre commented 5 days ago

@murilopereirame Thanks for submitting this issue. This is a bug in utilium, an upstream package I maintain. I'll fix this ASAP.

murilopereirame commented 5 days ago

@murilopereirame Thanks for submitting this issue. This is a bug in utilium, an upstream package I maintain. I'll fix this ASAP.

Great! Thanks for the quick response ;)

james-pre commented 5 days ago

I've confirmed the bug locally, working on a fix right now.

james-pre commented 5 days ago

@murilopereirame,

The bug was in an old version of utilium. It got fixed in utilium 0.4.0 but the ^0.3.4 version in package.json meant the fixed versions were not installed. 0.2.1 fixes the package.json version issue, as well as updated utilium to a fixed version.

Unfortunately, I now get this error:

TypeError: Invalid member for struct field
    at <project>/node_modules/utilium/dist/struct.js:66:19
    at Object._ [as uint16] (<project>/node_modules/utilium/dist/struct.js:163:28)
    at __esDecorate (<project>/node_modules/@zenfs/iso/dist/entries.js:19:40)
    at <project>/node_modules/@zenfs/iso/dist/entries.js:80:9
    at <project>/node_modules/@zenfs/iso/dist/entries.js:87:7
    at <project>/node_modules/@zenfs/iso/dist/entries.js:89:3
    at ModuleJob.run (node:internal/modules/esm/module_job:262:25)
    at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:482:26)
    at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:117:5)

I'm working on fixing this. I'll keep you updated.

james-pre commented 5 days ago

I can confirm this follow-up issue is an unpatched bug in utilium, working on a fix now.

james-pre commented 5 days ago

@murilopereirame,

The follow-up bug should be patched with @zenfs/iso 0.2.2 and utilium 0.6.0. The bug is now gone on my end. Could you please verify that you are no longer experiencing it so the issue can be closed? Thanks and have a great weekend!

murilopereirame commented 5 days ago

@murilopereirame,

The follow-up bug should be patched with @zenfs/iso 0.2.2 and utilium 0.6.0. The bug is now gone on my end. Could you please verify that you are no longer experiencing it so the issue can be closed? Thanks and have a great weekend!

Hey, I tried here, got this error now

file:///home/murilo.pereira/Repositories/tst/node_modules/@zenfs/iso/node_modules/utilium/dist/struct.js:67
        context.metadata[init] ||= [];
                         ^

TypeError: Cannot read properties of undefined (reading 'Symbol(struct_init)')
    at file:///home/murilo.pereira/Repositories/tst/node_modules/@zenfs/iso/node_modules/utilium/dist/struct.js:67:26
    at Object._structMemberDecorator [as uint16] (file:///home/murilo.pereira/Repositories/tst/node_modules/@zenfs/iso/node_modules/utilium/dist/struct.js:159:28)
    at __esDecorate (file:///home/murilo.pereira/Repositories/tst/node_modules/@zenfs/iso/dist/entries.js:19:40)
    at file:///home/murilo.pereira/Repositories/tst/node_modules/@zenfs/iso/dist/entries.js:80:9
    at file:///home/murilo.pereira/Repositories/tst/node_modules/@zenfs/iso/dist/entries.js:87:7
    at file:///home/murilo.pereira/Repositories/tst/node_modules/@zenfs/iso/dist/entries.js:89:3
    at ModuleJob.run (node:internal/modules/esm/module_job:262:25)
    at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:482:26)
    at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:117:5)

Node.js v22.8.0

package.json

{
  "name": "tst",
  "version": "1.0.0",
  "type": "module",
  "main": "tst.js",
  "dependencies": {
    "@zenfs/core": "^0.12.10",
    "@zenfs/iso": "^0.2.2"
  },
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "description": ""
}
james-pre commented 5 days ago

This is odd. What is the environment like? Please let me know:

You may need a polyfill since IsoFS uses Utilium's struct, which depends on decorators and decorator metadata.

murilopereirame commented 5 days ago

This is odd. What is the environment like? Please let me know:

  • version of Node.js
  • If you're using Typescript
  • If so, what version of Typescript

You may need a polyfill since IsoFS uses Utilium's struct, which depends on decorators and decorator metadata.

Pure js, Node.js v22.8.0

murilopereirame commented 5 days ago

Can you share your example? I can try here, maybe something is broken on my side

james-pre commented 5 days ago

@murilopereirame My code is the same as yours, though I used top-level await (which shouldn't make a difference, especially since the error appears to me on import.

Again, I've found that the error is unfortunatly with utilium.

It seems like decorator support is not very good.

Utilium v0.6.1 should fix it.

murilopereirame commented 4 days ago

@murilopereirame My code is the same as yours, though I used top-level await (which shouldn't make a difference, especially since the error appears to me on import.

Again, I've found that the error is unfortunatly with utilium.

It seems like decorator support is not very good.

Utilium v0.6.1 should fix it.

Apparently Utilium's build script is placing the build files in the wrong place. Moving inside node_modules from dist/src to dist solves this problems. All the previous problems were solved btw, thanks!

node:internal/modules/esm/resolve:257
    throw new ERR_MODULE_NOT_FOUND(
          ^

Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/home/murilo.pereira/Repositories/tst/node_modules/@zenfs/iso/node_modules/utilium/dist/index.js' imported from /home/murilo.pereira/Repositories/tst/node_modules/@zenfs/iso/dist/entries.js
    at finalizeResolution (node:internal/modules/esm/resolve:257:11)
    at moduleResolve (node:internal/modules/esm/resolve:914:10)
    at defaultResolve (node:internal/modules/esm/resolve:1038:11)
    at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:554:12)
    at ModuleLoader.resolve (node:internal/modules/esm/loader:523:25)
    at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:246:38)
    at ModuleJob._link (node:internal/modules/esm/module_job:126:49) {
  code: 'ERR_MODULE_NOT_FOUND',
  url: 'file:///home/murilo.pereira/Repositories/tst/node_modules/@zenfs/iso/node_modules/utilium/dist/index.js'
}

Node.js v22.8.0
james-pre commented 4 days ago

@murilopereirame,

Sorry again for the continued issues. Utilium 0.6.2 should fix the bug. It looks like when I added the test TS file, it changed the organization of the dist directory, resulting in invalid imports. I hope Utilium 0.6.2 can finally fix everything. Please let me know.

murilopereirame commented 3 days ago

Member

Hey, no more errors! Thanks for the hard work ;)

james-pre commented 3 days ago

@murilopereirame, glad I could help! Please let me know if you have any issues, or would like a feature added!