Search code examples
javascriptnode.jstypescriptglobnode-webkit

File pattern in NW.js: package.json not found in srcDir file glob patterns


My source folder is /dist, and I want to run a NW.js script in /tool/nw.js. Why does it throw the glob pattern error about not finding the srcDir (/dist) folder? It works when using glob:false in the config but I want to know why the srcDir: "../dist" is wrong.

My folder structure

/
  /build

  /dist
      /html
      package.json

  /tool
    run.js
 

/tool/run.js

    await nwbuild({
      platform: "linux",
      arch: "x64",
      srcDir: "../dist",
      outDir: "../build/linux64",
      glob: true // true by default
    });

Solution

  • If globbing is enabled and you set srcDir to ../dist, then nw-builder will only "glob" the ../dist directory without going through its contents.

    To get all files and folders: ../dist/**/*.*

    To get files and folders one level deep: ../dist/*

    To learn more about file globbing: https://github.com/isaacs/node-glob?tab=readme-ov-file#glob-primer