NW.js (Node-Webkit) Error: package.json not found in srcDir file glob patterns

1.3k Views Asked by At

I'm new to NW.js but my debut project was quite a walk-through until I got to Production and got stuck. I've tried Google search, but to no avail.

On my package.json file, I have:

... "scripts": { "dev": "nw source/", "prod": "nwbuild source/ --mode run -p win64 --buildDir dist/" },

npm run dev works, but npm run prod fails with following error message:

[ ERROR ] 2023-01-28T12:38:42.542Z package.json not found in srcDir file glob patterns

Also, used the CLI to try the command: npm nwbuild ./ --mode=run --version=latest --flavor=sdk, but with no result, except that the version number (9.3.1), was returned.

Error message

Checked this forum and some others, for similar issues. Though nothing specific enough found, but I tried all related advice and suggestions. This included Node-js and NW.js versions tweaks and changes in settings but no success yet.

I need something more specific to the error message:

[ ERROR ] 2023-01-28T12:38:42.542Z packeage.json not found in srcDir file glob patterns

Same error message mostly persisted:

Error message

OS is Windows 11, and Windows 10 also.

2

There are 2 best solutions below

2
Ayush C. On

nw-builder uses file globbing (as of v4.0.9). The package.json not found in srcDir file glob patterns error usually occurs when an incorrect globbing pattern has been used. You can try changing the command to (or something similar):

npx nwbuild ./**/* --mode=run --version=latest --flavor=sdk

It requires a globbing pattern since it needs to find a valid package.json before running or building the application.

Turns out this is a bug in nw-builder. As a temporary workaround, you can use nw-builder via JavaScript module.

2
abby On

I was stuck in this for a long time. Try my solution: Firstly update to latest version -

I tried with versions =>

nw : 0.77.0, nw-builder : 4.3.2, nodeJs : 20.1.0

Then change the scripts in package.json as there has been few changes for nw-build from version 3 to 4:

 "scripts": {
    "dev": "nw src/",
    "prod": "nwbuild --platform win --arch x64 --outDir dist/src --glob=false src"
  },

This worked for me, it may be helpful for anyone struggling with this. Thank you :)