Skip to content

Dirent.parentPath is missing from fs.glob/globSync withFileTypes under asar #51838

@Lastor-Chen

Description

@Lastor-Chen

Preflight Checklist

Electron Version

42.2.0

What operating system(s) are you using?

macOS

Operating System Version

macOS Ventura 13.5 (arm64), Windows 11 25H2 (x64)

What arch are you using?

arm64 (including Apple Silicon)

Last Known Working Electron version

No response

Does the issue also appear in Chromium / Google Chrome?

No

Expected Behavior

fs.glob or fs.globSync with options.withFileTypes expect to return fs.Dirent[] under asar packaged or not. And the fs.Dirent should include a parentPath property.

// dist/index.js
import fs from 'node:fs'
import path from 'node:path'

const direntList = fs.globSync('*.js', { cwd: import.meta.dirname, withFileTypes: true })
/*
[
  Dirent {
    name: 'index.js',
    parentPath: '/path/to/project/dist',
    Symbol(type): 1
  }
]
*/

Actual Behavior

Dirent.parentPath property is existing under dev runtime npx electron . or build asar: false, but it's missing under asar packaged.

// under asar packaged app
// dist/index.js
import fs from 'node:fs'
import path from 'node:path'
import { dialog } from 'electron'

const direntList = fs.globSync('*.js', { cwd: import.meta.dirname, withFileTypes: true })

// Use showErrorBox to print value after build app.
dialog.showErrorBox('', JSON.stringify(direntList, null, 2))
/*
[
  {
    "name": "index.js"
    // parentPath is missing
  }
]
*/

Dirent.parentPath is a relatively new property. It's marked stable in node.js v24.0.0 and v22.17.0. Maybe hasn't been implemented yet in electron asar mode.
https://nodejs.org/api/fs.html#direntparentpath

Testcase Gist URL

No response

Additional Information

The following steps can be used to reproduce the result. Using node.js v24.15.0 same with electron's node.js version.

  1. Create a new npm project directory and enter it
$ mkdir electron-test
$ cd electron-test
$ npm init --y
  1. Install dependencies
$ npm install -D electron@42.2.0 electron-builder@26.8.1
  1. Edit electron-builder config in package.json
// package.json
{
  // ...
  // add the following
  "main": "dist/index.js",
  "type": "module",
  "build": {
    "appId": "some.app.id",
    "compression": "store",
    "asar": true,
    "directories": {
      "output": "release"
    }
  }
}
  1. Add dist/index.js
// dist/index.js
import fs from 'node:fs'
import path from 'node:path'
import { app, dialog } from 'electron'

const direntList = fs.globSync('*.js', { cwd: import.meta.dirname, withFileTypes: true })

// print value
console.log(direntList)
dialog.showErrorBox('', JSON.stringify(direntList, null, 2))

app.exit()
  1. Run npx electron . the Dirent.parentPath exists
  2. Run npx electron-builder to build app with asar
  3. Click to launch the packaged app, we can see the Dirent.parentPath is missing in the dialog

Metadata

Metadata

Assignees

No one assigned

    Type

    No fields configured for Bug.

    Projects

    Status
    🔄 Follow Up Before Stable

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions