Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

removing devDependencies from package.json breaks levelup in electron #1408

Closed
blahah opened this issue Mar 27, 2017 · 4 comments · May be fixed by qcif/data-curator#563
Closed

removing devDependencies from package.json breaks levelup in electron #1408

blahah opened this issue Mar 27, 2017 · 4 comments · May be fixed by qcif/data-curator#563
Labels

Comments

@blahah
Copy link

@blahah blahah commented Mar 27, 2017

  • Version: 16.3.0
  • Target: 1.6.4

Problem

This function which was introduced as a result of this issue deletes some properties from the package.json of everything in the app's node_modules. The problem is that some modules use the information in their own package.json, including those deleted fields, at runtime.

An example is levelup. Requiring levelup in an app packaged with electron-builder@16.3.0 leads to the following error:

/Applications/ScienceFair.app/Contents/Resources/app/node_modules/levelup/lib/util.js:32 Uncaught TypeError: Cannot read property 'leveldown' of undefined
    at getLevelDOWN (/Applications/ScienceFair.app/Contents/Resources/app/node_modules/levelup/lib/util.js:32:68)
    at LevelUP.open (/Applications/ScienceFair.app/Contents/Resources/app/node_modules/levelup/lib/levelup.js:114:37)
    at new LevelUP (/Applications/ScienceFair.app/Contents/Resources/app/node_modules/levelup/lib/levelup.js:87:8)
    at LevelUP (/Applications/ScienceFair.app/Contents/Resources/app/node_modules/levelup/lib/levelup.js:47:12)
    at new Yuno (/Applications/ScienceFair.app/Contents/Resources/app/node_modules/yunodb/index.js:40:19)
    at Yuno (/Applications/ScienceFair.app/Contents/Resources/app/node_modules/yunodb/index.js:23:39)
    at module.exports (/Applications/ScienceFair.app/Contents/Resources/app/client/lib/localcollection.js:41:3)
    at start (file:///Applications/ScienceFair.app/Contents/Resources/app/client/index.js:37:35)
    at file:///Applications/ScienceFair.app/Contents/Resources/app/client/index.js:10:1

The problem is that levelup is using the devDependencies field to provide information about itself, but the field has been deleted.

Possible solution

I would suggest that although levelup's behaviour isn't ideal, there's no reason why any module should expect fields to be deleted from its package.json. How about having an option to preserve all the fields in package.json of all node_modules?

Alternatively, the change could be reverted. It probably only saves a small amount of size in a packaged app.

blahah added a commit to sciencefair-land/sciencefair that referenced this issue Mar 27, 2017
@develar develar added the bug label Mar 27, 2017
@develar develar closed this in 0278efb Mar 27, 2017
@blahah
Copy link
Author

@blahah blahah commented Mar 27, 2017

That was incredibly quick - thanks for the great work you're doing on this ecosystem, and for resolving this in particular so rapidly.

@orlandodemauro
Copy link

@orlandodemauro orlandodemauro commented Sep 1, 2017

Hi all,

I´m having the same issue. using linvodb3 that uses leveldb

node v6.11.0
I have all the file of my app in the dist folder with a package.json like

 {
  "name": "st26-electron",
  "version": "0.1.0",
  "license": "MIT",
  "main": "main.js",
  "scripts": {
    "postinstall": "npm run rebuild",
    "rebuild": "../node_modules/.bin/electron-rebuild"
  },
  "dependencies": {
    "async": "^2.5.0",
    "babel-core": "^6.25.0",
    "babel-polyfill": "^6.23.0",
    "bluebird": "^3.5.0",
    "body-parser": "^1.12.4",
    "express":"^4.13.3",
    "events": "^1.1.1",
    "fs": "0.0.1-security",
    "http": "0.0.0",
    "jquery": "3.2.1",
    "linvodb3": "^3.25.0",
    "levelup":"1.3.9",
    "leveldown": "^1.7.2",
    "stream": "0.0.2",
    "util": "^0.10.3",
    "websocket": "^1.0.24"
  }

}

and in the root of the project I have a package.json like:

"build": {
    "files": {
      "from": "dist/",
      "filter": [
        "**/*",
        "!server/test/**/*"
      ]
    },
    "dmg": {
      "contents": [
        {
          "x": 130,
          "y": 220
        }
      ]
    },
    "win": {
      "target": [
        "nsis"
      ]
    },
    "linux": {
      "target": [
        "deb",
        "AppImage"
      ]
    },
    "directories": {
      "buildResources": "resources",
      "output": "release"
    }
  },
"scripts": {
    "pack": "electron-builder --dir",
    "build": "electron-builder",
    "build:osx": "electron-builder -m",
  },
"devDependencies": {
    "@angular/cli": "1.0.4",
    "@angular/compiler-cli": "4.1.3",
    "@types/fullcalendar": "2.7.40",
    "@types/jasmine": "2.5.38",
    "@types/jquery": "2.0.41",
    "@types/jquery.slimscroll": "1.3.30",
    "@types/lodash": "4.14.61",
    "@types/node": "6.0.69",
    "babel-cli": "^6.24.1",
    "babel-preset-es2015": "^6.24.1",
    "babel-preset-stage-0": "^6.24.1",
    "chai": "^3.5.0",
    "chai-http": "^3.0.0",
    "codelyzer": "3.0.1",
    "copyfiles": "1.2.0",
    "electron": "1.7.5",
    "node-gyp-build": "^3.2.0",
    "electron-builder": "^19.27.3",
    "electron-packager": "^9.0.0",
    "electron-rebuild": "^1.5.11",
    "electron-reload": "1.2.1",
    "gh-pages": "0.12.0",
    "gulp": "^3.9.1",
    "gulp-babel": "^6.1.2",
    "jasmine-core": "2.5.2",
    "jasmine-spec-reporter": "3.2.0",
    "karma": "1.4.1",
    "karma-chrome-launcher": "2.0.0",
    "karma-cli": "1.0.1",
    "karma-coverage-istanbul-reporter": "0.2.0",
    "karma-jasmine": "1.1.0",
    "karma-jasmine-html-reporter": "0.2.2",
    "mocha": "^3.2.0",
    "npm-run-all": "4.0.2",
    "protractor": "5.1.0",
    "rimraf": "2.6.1",
    "standard-changelog": "1.0.1",
    "stylelint": "7.10.1",
    "ts-node": "2.1.2",
    "tslint": "5.2.0",
    "tslint-eslint-rules": "4.0.0",
    "tslint-language-service": "0.9.6",
    "typescript": "2.3.2",
    "typogr": "0.6.6",
    "underscore": "1.8.3",
    "wintersmith": "2.2.5",
    "wintersmith-sassy": "1.1.0"
  }
}

it is building on window with no error bu on mac where I´m getting the following error when opening the app

/Users/Desktop/PROJECT001/release/mac/ST.app/Contents/Resources/app.asar/node_modules/levelup/lib/leveldown.js:8 Uncaught TypeError: Cannot read property 'leveldown' of undefined
    at getLevelDOWN (/Users/Desktop/PROJECT001/release/mac/ST.app/Contents/Resources/app.asar/node_modules/levelup/lib/leveldown.js:8:67)
    at LevelUP.open (/Users/Desktop/PROJECT001/release/mac/ST.app/Contents/Resources/app.asar/node_modules/levelup/lib/levelup.js:112:34)
    at new LevelUP (/Users/Desktop/PROJECT001/release/mac/ST.app/Contents/Resources/app.asar/node_modules/levelup/lib/levelup.js:84:8)
    at LevelUP (/Users/Desktop/PROJECT001/release/mac/ST.app/Contents/Resources/app.asar/node_modules/levelup/lib/levelup.js:45:44)
    at Function.Model.initStore (/Users/Desktop/PROJECT001/release/mac/ST.app/Contents/Resources/app.asar/node_modules/linvodb3/lib/model.js:79:100)
    at new Model (/Users/Desktop/PROJECT001/release/mac/ST.app/Contents/Resources/app.asar/node_modules/linvodb3/lib/model.js:52:35)
    at Object.<anonymous> (/Users/Desktop/PROJECT001/release/mac/ST.app/Contents/Resources/app.asar/server/models/project.js:25:18)
    at Object.<anonymous> (/Users/Desktop/PROJECT001/release/mac/ST.app/Contents/Resources/app.asar/server/models/project.js:27:3)
    at Module._compile (module.js:571:32)
    at loader (/Users/Desktop/PROJECT001/release/mac/ST.app/Contents/Resources/app.asar/node_modules/babel-register/lib/node.js:144:5)
    at Object.require.extensions.(anonymous function) [as .js] (/Users/Desktop/PROJECT001/release/mac/ST.app/Contents/Resources/app.asar/node_modules/babel-register/lib/node.js:154:7)

I noticed that if i replace the postinstall in the dist/package.json with

"cd node_modules/leveldown && node-gyp rebuild --target=1.7.5 --dist-url=https://atom.io/download/atom-shell"

I´m able to run the app with "electron ./dist" but not using the result from the builder.

I don´t know what else I can try. thank you guys for any help that you could provide

@develar
Copy link
Member

@develar develar commented Sep 1, 2017

@orlandodemauro

"electron-packager": "^9.0.0",
"electron-rebuild": "^1.5.11",

both these deps are not required.

Fixed in 19.27.4 (will be available in 1 hour).

@orlandodemauro
Copy link

@orlandodemauro orlandodemauro commented Sep 1, 2017

@develar thanks a million for your quick fix and response. Never got a fix in such a short time :) thanks a lot for.the work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

3 participants