Electron-builder: Confused by 2 package.json structure

Created on 18 Jul 2016  Â·  10Comments  Â·  Source: electron-userland/electron-builder

  • Version: 5.12.1

  • Target: win32

I guess I'm confused by the two-package.json structure.

I am use to installing things with npm, which means everything is specified in /package.json (what you call the development package.json). But electron-builder gives me errors or deprecation messages for having fields like "homepage" and "license" in my /package.json. However, /app/package.json (what you call the application package.json) is not allowed to have "build" and other fields, so neither file feels "complete".

  1. I definitely have to put my app's dependencies in /app/package.json, but do I need to put them in /package.json too? Or is /package.json just used for build tool dependencies?
  2. Which would you put on npm?

If I make /package.json the npm module, then the dependencies listed would be build dependencies rather than app dependencies, and electron-builder is going to fuss about homepage and license fields. But if I make /app/package.json the npm module, then it will not install the build dependencies, and the npm module will be a folder inside my github repo rather than the github repo.

  1. Why can't you just have an "electronDependencies" section in /package.json, and then derive /app/package.json during the build?

Having two keep two separate package.json's in sync (particularly the "version" field, but also "description", "homepage" etc) is just inviting me to screw up. I'd much prefer a single source of truth.

question

Most helpful comment

@akashnimare Please file new issue and describe why it doesn't work for you.

can you point me to an example app which uses single packge.json?

https://github.com/electron-userland/electron-builder/tree/master/test/fixtures/test-app-one

All 10 comments

If you don't have native dependencies — just use one-package.json structure.
Maybe you will need to exclude some files using https://github.com/electron-userland/electron-builder/wiki/Options#BuildMetadata-files in this case.

But electron-builder gives me errors or deprecation messages for having fields like "homepage" and "license" in my /package.json.

These fields are standard — not in the build, but in the root.

I definitely have to put my app's dependencies in /app/package.json, but do I need to put them in /package.json too? Or is /package.json just used for build tool dependencies?

No, "/package.json just used for build tool dependencies"

Which would you put on npm?

Do you mean publish?

(particularly the "version" field, but also "description", "homepage" etc) is just inviting me to screw up

Why? See https://github.com/develar/onshape-desktop-shell/blob/master/package.json — only app package.json contains these fields.

Which would you put on npm?

Do you mean publish?

Yes, exactly. Am I supposed to run "npm publish" in the / or in the /app?

If you don't have native dependencies — just use one-package.json structure.

I read somewhere to use two. I will try one. Thank you for making such a powerful tool!

I read somewhere to use two.

Since version 5 the most major issue is solved — you don't need anymore to use two-package.json structure to avoid dev dependencies in your production electron app — electron-builder 5+ correctly filter such dependencies without any configuration.

Alright, I can confirm that using one-package.json structure seems to work but ONLY if you do not have a directory named "app". If I renamed "app" to "src" (and updated package.json accordingly) it works fine, but if I have an "app" directory, I get this error:

Error: ENOENT: no such file or directory, open 'E:\git\ransomAware\app\package.json'
    at Error (native)
From previous event:
    at Packager.<anonymous> (E:\git\ransomAware\node_modules\electron-builder\src\packager.ts:73:55)
    at next (native)
    at processImmediate [as _immediateCallback] (timers.js:383:17)
From previous event:
    at tsAwaiter (E:\git\ransomAware\node_modules\electron-builder\src\util\awaiter.ts:10:47)
    at Object.build (E:\git\ransomAware\node_modules\electron-builder\src\builder.ts:193:52)
    at Object.<anonymous> (E:\git\ransomAware\node_modules\electron-builder\src\build-cli.ts:27:28)
    at Module._compile (module.js:398:26)
    at Object.Module._extensions..js (module.js:405:10)
    at Module.load (module.js:344:32)
    at Function.Module._load (module.js:301:12)
    at Function.Module.runMain (module.js:430:10)
    at startup (node.js:141:18)
    at node.js:980:3

Should I file this as a bug?

@wmhilton Thanks for report, fixed.

Awesome!

@develar can you point me to an example app which uses single packge.json? I'm having hard time making it work.

@akashnimare Please file new issue and describe why it doesn't work for you.

can you point me to an example app which uses single packge.json?

https://github.com/electron-userland/electron-builder/tree/master/test/fixtures/test-app-one

@akashnimare also my project is a real example: https://github.com/wmhilton/ransomAware?files=1

@develar that example is confusing. Why there's a package.json directory in the app folder?

Is there a writeup somewhere about what folders are implied by electron or electron-builder? 'cause I seem to have name conflict in my project (I have app and dist folder, but I feel that I'm using it in a different context than electron expects)

Was this page helpful?
0 / 5 - 0 ratings