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

StackOverflow https://stackoverflow.com/questions/22787613

  •  25-06-2023
  •  | 
  •  

Pregunta

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:

https://github.com/rogerwang/node-webkit/issues/1503

I wonder if anyone else is experiencing this, and what you might have done to resolve this issue?

Here's some relevant information about my app.

node-webkit: v0.8.5
node.js: v0.10.22
Chromium: 30.0.1599.66
bower: 1.3.1
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"
  }
}
¿Fue útil?

Solución

So, there is a bug logged for this in the nodewebkit repo, but I did find a workaround for now. Go into the node_modules directory (where nodewebkit is installed) in the nodewebkit directory, and rename package.json to _package.json.

It seems that there is a conflict with the package.json and the read order of the files.

So something like 'cd [path to node modules]/node_modules/nodewebkit;mv package.json _package.json' should do it.

PLEASE NOTE: This is just a workaround, they should be releasing a fix (hopefully) soon, but until they do...

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top