Running NodeWebkit app fails with: Invalid package.json Field 'main' is required error

11 views
Skip to first unread message

andy matthews

unread,
Mar 31, 2014, 5:30:24 PM3/31/14
to node-...@googlegroups.com
I've been working with my NW app for a few weeks now without issue. I'm starting to bring other coworkers into my repo for testing and I decided to write an install script rather than forcing them to manually install the dependencies. Today, after running the install script to test, I tried running my app and got the following error:

Invalid package.json
Field 'main' is required.

I made no changes to my application, or to my package.json file. I can't figure out what might be causing the problem, but there does appear to be an open issue on NW's GitHub repo which talks about this:


I wonder if anyone else is experiencing this? Here's some relevant information about my app.

$ node -v                  
v0.10.26

$ bower -v
1.3.1

$ yo -v (yeoman)
1.1.2

I tried to get version for nodewebkit itself, but the command `nodewebkit` doesn't offer a version flag.

The install shell script

npm install bower -g
npm install yeoman -g
npm install generator-node-webkit -g
npm install nodewebkit -g
npm install grunt-cli -g
bower install
npm install


My directory tree (from root):
├── Gruntfile.js
├── app
│   ├── css
│   │   ├── main.css
│   ├── index.html
│   ├── js
│   │   ├── application.js
│   └── package.json
├── bower.json
├── package.json
My innermost package.json file, within my main app directory:
{
    "name": "directory",
    "main": "index.html",
    "version": "0.0.1",
    "single-instance": true,
    "window": {
        //"toolbar": false,
        "title": "Directory",
        "width": 850,
        "height": 600,
        "min_width": 850,
        "min_height": 600
    },
    "chromium-args": "--child-clean-exit"
}
And here's the outermost package.json:
{
  "name": "directory",
  "version": "0.0.0",
  "main": "app/index.html",
  "description": "",
  "keywords": [],
  "dependencies": {
    "xls-to-json": "~0.2.0"
  },
  "devDependencies": {
    "matchdep": "~0.1.2",
    "grunt": "~0.4.1",
    "grunt-contrib-copy": "~0.4.1",
    "grunt-contrib-sass": "~0.4.1",
    "grunt-contrib-concat": "~0.1.3",
    "grunt-contrib-jshint": "~0.4.3",
    "grunt-contrib-clean": "~0.4.1",
    "grunt-contrib-rename": "0.0.3",
    "grunt-contrib-compress": "~0.5.3",
    "xls-to-json": "~0.2.0"
  },
  "engines": {
    "node": ">=0.8.0"
  }
}


pca...@gmail.com

unread,
Mar 31, 2014, 8:27:13 PM3/31/14
to node-...@googlegroups.com
If you type nw:version in the adress bar of nw, you will have the version numbers of all the components

andy matthews

unread,
Apr 1, 2014, 9:24:51 AM4/1/14
to node-...@googlegroups.com, pca...@gmail.com
Ah, excellent! Version added.

andy matthews

unread,
Apr 1, 2014, 9:25:27 AM4/1/14
to node-...@googlegroups.com
Here's the additional version information I was missing:

node-webkit v0.8.5
node.js v0.10.22
Chromium 30.0.1599.66

andy matthews

unread,
Apr 2, 2014, 12:20:12 PM4/2/14
to node-...@googlegroups.com
I even tried deleting my local repo, redownloading it, and reinstalling dependencies. Still having the same problem. Comparing the version information between my home machine (which can still run the app) and my work machine (which cannot run the app), it looks like bower is the only difference. I can't see that being the cause though.

Work machine (cannot run the app):

node-webkit: v0.8.5
node.js: v0.10.22
Chromium: 30.0.1599.66
bower: 1.3.1
yeoman: 1.1.2 

Home machine (can run the app):

node-webkit v0.8.5
node.js v0.10.22
Chromium 30.0.1599.66
bower: 1.2.8
yeoman: 1.1.2

Laszlo Z. Antal

unread,
Apr 2, 2014, 12:57:45 PM4/2/14
to node-...@googlegroups.com
Hi,

On Apr 2, 2014, at 9:20, andy matthews <an...@commadelimited.com> wrote:

I even tried deleting my local repo, redownloading it, and reinstalling dependencies. Still having the same problem. Comparing the version information between my home machine (which can still run the app) and my work machine (which cannot run the app), it looks like bower is the only difference. I can't see that being the cause though.

Can you post your package.json file?

Laszlo


Work machine (cannot run the app):

node-webkit: v0.8.5
node.js: v0.10.22
Chromium: 30.0.1599.66
bower: 1.3.1
yeoman: 1.1.2 

Home machine (can run the app):

node-webkit v0.8.5
node.js v0.10.22
Chromium 30.0.1599.66
bower: 1.2.8
yeoman: 1.1.2

--
You received this message because you are subscribed to the Google Groups "node-webkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-webkit...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

andy matthews

unread,
Apr 2, 2014, 9:33:47 PM4/2/14
to node-...@googlegroups.com
LZAntal, I posted both package.json files in the first post in this thread. I have one in my project's root (used for npm install), and the other is contained within my app root (used as manifest).

Laszlo Z. Antal

unread,
Apr 2, 2014, 11:25:32 PM4/2/14
to node-...@googlegroups.com
Hi,

On Apr 2, 2014, at 18:33, andy matthews <an...@commadelimited.com> wrote:

LZAntal, I posted both package.json files in the first post in this thread. I have one in my project's root (used for npm install), and the other is contained within my app root (used as manifest).

Weird it doesn't show up in this thread. I wonder if nw reads your other package.json file and that's why it can't find the main in it. 

Laszlo

andy matthews

unread,
Apr 3, 2014, 1:03:33 AM4/3/14
to node-...@googlegroups.com
Oh, I'm looking at this on the Groups web app. I deleted past history in that post so as not to clog things up. It feels like it's reading SOME other package.json file, but which one I can't determine since it happens as soon as the app loads. I tried putting a main property in the other file too just in case...didn't seem to make a difference.

Marc Torruella

unread,
Apr 3, 2014, 1:42:33 AM4/3/14
to node-...@googlegroups.com

I had this problem too... I solved it having all nodejs packages inside the correct directory... Which name i dont remember :-(. Its on nodewebkit github main doc.

Outside of this directory i had only one package.json, the one nodewebkit will use

El dia 03/04/2014 7:03, "andy matthews" <an...@commadelimited.com> va escriure:

Chris Price

unread,
Apr 3, 2014, 6:21:39 AM4/3/14
to node-...@googlegroups.com
package.json for the app (innermost -- the one with the window options in it) should be in the same directory as nw.exe in order for it to be picked up properly. My best guess as to what's happening is exactly what Laszlo says -- it's reading the npm package.json and not your app's package.json.

If you drop the app folder onto nw.exe, it should open normally. If opening with a shortcut, try: 

(I'm assuming Windows here, but the other platforms should be either exactly the same or similar)

[path]\nw.exe [path]\app\ (relative may work for the second path depending on where nw.exe is - i'm not sure)

as the target (with quotes as needed).

The same should work on the command line.

andy matthews

unread,
Apr 3, 2014, 10:41:59 AM4/3/14
to node-...@googlegroups.com
Chris...

Could you be a little more clear please? I might be confused because I don't understand the process NW uses to load the app. Is it loading within my project directory, or is it building it somewhere else and running it from there? If it is running it from another location how can I find that location so that I can inspect it?

I should also say that I'm running OSX Mavericks. Here's an image of my project's directory tree with (what I think are) the relevant bits:


It shows the app directory with inner package.json, as well as the outer files including what I think are the NW binaries in the resources directory.

Chris Price

unread,
Apr 3, 2014, 2:24:22 PM4/3/14
to node-...@googlegroups.com
The innermost package.json (the one node-webkit uses) should be where the outermost package.json is currently. You can combine these files without issue in my experience (as long as the properties shared between npm and node-webkit follow all of the rules associated with both [such as no spaces in the name]). You can also add a "private" property so your app isn't accidentally uploaded to npm.

{
   ...
   "private" : true
   ...
}

Using this method, your app should run directly from the app folder and not some other location. 


For final packaging, since you're on Mac, the best way I've found (borrowed from the Prepros project) is to place your app's files inside of node-webkit.app. In the end your directory structure of the app package would look like this:

node-webkit.app (or renamed to your app's name)
-- /Contents
---- /Frameworks
---- /MacOS
---- /Resources
------ /app.nw -- just a folder named app.nw
-------- /app
---------- package.json
---------- /node_modules
---------- [all of your other app files]



andy matthews

unread,
Apr 3, 2014, 4:25:30 PM4/3/14
to node-...@googlegroups.com
Interesting. This is my first NW app so it's def a little bit of a learning curve. This could also explain another issue I'm having where my Node dependencies don't exist when the app is run on someone else's computer:


Thanks for your time Chris.



andy
Reply all
Reply to author
Forward
0 new messages