electron-builder icon indicating copy to clipboard operation
electron-builder copied to clipboard

failedTask=build stackTrace=TypeError: The "path" argument must be of type string. Received undefined

Open dingshaohua-com opened this issue 10 months ago • 16 comments

 electron-builder  version=26.0.6 os=24.3.0
  • loaded configuration  file=/Users/dsh/files.localized/code/live-student-fe/src/apps/electron/electron-builder.json
  • description is missed in the package.json  appPackageFile=/Users/dsh/files.localized/code/live-student-fe/src/apps/electron/package.json
  • writing effective config  file=/Users/dsh/files.localized/code/live-student-fe/dist/builder-effective-config.yaml
  • executing @electron/rebuild  electronVersion=22.3.27 arch=x64 buildFromSource=false appDir=./
  • installing native dependencies  arch=x64
  • completed installing native dependencies
  • packaging       platform=darwin arch=x64 electron=22.3.27 appOutDir=/Users/dsh/files.localized/code/live-student-fe/dist/mac-universal-x64-temp
  ⨯ The "path" argument must be of type string. Received undefined  failedTask=build stackTrace=TypeError: The "path" argument must be of type string. Received undefined
    at Object.normalize (node:path:1206:5)
    at flatten (/Users/dsh/files.localized/code/live-student-fe/node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/app-builder-lib/src/node-module-collector/nodeModulesCollector.ts:64:49)
    at flatten (/Users/dsh/files.localized/code/live-student-fe/node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/app-builder-lib/src/node-module-collector/nodeModulesCollector.ts:69:9)
    at flatten (/Users/dsh/files.localized/code/live-student-fe/node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/app-builder-lib/src/node-module-collector/nodeModulesCollector.ts:69:9)
    at flatten (/Users/dsh/files.localized/code/live-student-fe/node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/app-builder-lib/src/node-module-collector/nodeModulesCollector.ts:69:9)
    at flatten (/Users/dsh/files.localized/code/live-student-fe/node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/app-builder-lib/src/node-module-collector/nodeModulesCollector.ts:69:9)
    at flatten (/Users/dsh/files.localized/code/live-student-fe/node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/app-builder-lib/src/node-module-collector/nodeModulesCollector.ts:69:9)
    at NpmNodeModulesCollector.convertToDependencyGraph (/Users/dsh/files.localized/code/live-student-fe/node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/app-builder-lib/src/node-module-collector/nodeModulesCollector.ts:73:5)
    at NpmNodeModulesCollector.getNodeModules (/Users/dsh/files.localized/code/live-student-fe/node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/app-builder-lib/src/node-module-collector/nodeModulesCollector.ts:155:34)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)

dingshaohua-com avatar Feb 17 '25 03:02 dingshaohua-com

Can you provide a reproducible demo? Or share the dependencies and devDependencies of your project?

beyondkmp avatar Feb 17 '25 04:02 beyondkmp

I saw this during my refactoring and wasn't sure if it was caused by my code tbh, but there should be some safeguards added in https://github.com/electron-userland/electron-builder/pull/8872 that might resolve this.

mmaietta avatar Feb 18 '25 00:02 mmaietta

Seeing the same issue with 26.0.6, mac only, with native dependencies as well. The stacktrace seems similar to #8842

lishid avatar Feb 18 '25 15:02 lishid

@lishid could you share a minimum reproducible repo or at least your package.json so that we can replicate the issue on our side?

Also can you please try 26.0.7? The release includes an additional fix for the node module collector logic.

mmaietta avatar Feb 18 '25 16:02 mmaietta

Apologies, I meant to say I was using 26.0.7. Our package.json has two internal native dependencies (plus @electron/remote) so it's a bit difficult to share, but I will try and see if I can get a minimal repro setup.

Not sure if this is related, but the internal native dependencies are imported from an upper level directory (../package-name) and are symlinked into node_modules. Previously in 25.x we've ran into the issue where electron-builder wasn't happy with out-of-directory dependencies (the "must be under" error) which has been resolved since upgrading to v26.

lishid avatar Feb 18 '25 17:02 lishid

For native dependencies, deps I like to use to test with is node-mac-permissions and sqlite3, but it sounds like your project may be too unique for that to suffice.

For a minimum repro, I use electron-quick-start project as a template to get easily/quickly set up. Hope that helps!

mmaietta avatar Feb 18 '25 17:02 mmaietta

Ok I've found the cause of my issue after tracing through the code execution. It seems that we had @electron/remote specified in the package.json inside our app directory (using the two package.json structure) but it was not npm i'ed. I guess in previous versions of electron-builder this may have worked because we also have a copy of it installed in the upper level.

I noted that in nodeModulesCollector.ts > convertToDependencyGraph(tree) > flatten we are seeing the following dependency object, where the lack of a path property triggers this error.

"@electron/remote": {
  required: '2.1.2',
  missing: true,
  problems: [ 'missing: @electron/[email protected], required by [email protected]' ]
}

lishid avatar Feb 18 '25 18:02 lishid

@lishid In your internal native dependencies, are their dependencies installed via yarn or npm install firstly? If not, it could potentially lead to this error. This is because the required dependencies cannot be found within your internal native dependencies.

In previous implementations, if a dependency couldn't be found, it would simply be ignored without throwing an error, and the project would directly use a dependency with the same name from the current project, which might result in version

beyondkmp avatar Feb 19 '25 00:02 beyondkmp

Our internal dependences are simply checked into the repo, and they are referred to using npm dependency as "package": "../package". It seems that in this case npm automatically made a symlink to the folder. However the error here seems to be the missing @electron/remote which behaved as you described - silently ignored and automatically using the current project's copy, but since the upgrade it had errored out because it was somehow missing in the app's node modules.

I've performed an npm install in the app directory which installed the missing dep and the error is gone, all is good for now.

I am reporting back because this error is lacking in details and that makes debugging difficult. I think a reasonable improvement could be to check the value here and terminate with an appropriate error message, rather than letting path.normalize error out because undefined was passed in.

lishid avatar Feb 19 '25 00:02 lishid

I'm adding additional logging in https://github.com/electron-userland/electron-builder/pull/8872 as part of the refactor. It also adds some safeguards in but I'll double-check the setup to see if I can replicate your configuration. I'm also adding additional error/debug logging, such as when the dependency is missing a path

mmaietta avatar Feb 19 '25 00:02 mmaietta

Any news on this bug? still getting same error on the latest version on mac OS.

lucadido06 avatar Apr 24 '25 13:04 lucadido06

Latest version of macOS or most recent release of electron-builder (v26.0.13) while building on macOS?

mmaietta avatar Apr 24 '25 14:04 mmaietta

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 30 days.

github-actions[bot] avatar May 25 '25 00:05 github-actions[bot]

Yeah I get the same with 26.0.13 on macos, perhaps an indicator might be that I am using a pnpm workspace monorepo

EDIT: I have successfully been able to build it on 26.0.3 It seems that I will get this error anything that is under 26.0.6

⨯ The "path" argument must be of type string. Received undefined failedTask=build stackTrace=TypeError: The "path" argument must be of type string. Received undefined

and anything over 26.0.6 I will get this error

  ⨯ dependency path is undefined  packageName=@electron-toolkit/preload data=[object Object] parentModule=outdraw.ai parentVersion=1.0.0
  ⨯ unable to parse `path` during `tree.dependencies` reduce  failedTask=build stackTrace=Error: unable to parse `path` during `tree.dependencies` reduce

kyeshmz avatar Jun 01 '25 17:06 kyeshmz

@kyeshmz I have the same problem, did you find a solution?

anis-dr avatar Oct 17 '25 18:10 anis-dr

Working on this in https://github.com/electron-userland/electron-builder/pull/9309

mmaietta avatar Oct 17 '25 23:10 mmaietta