Signup for the Ionic Newsletter to get the latest news and updates!

  • Luis Ruiz Figueroa

    tengo el siguiente error

    • Kerpanic

      make sure you run `npm install jshint async –save`.

  • Kerpanic

    But how do you pass jsHint configs when feeding it the source code from stdin?
    ionic uses AngularJS and you need different tuning.

  • https://securiteam.io Shadi Habbal

    I prefer using gulp-jshint in a hook as it’s much more cleaner and easier to iterate over directories and pass config to jshint.

    sample code: http://pastebin.com/KSAPhfLy

  • Mike M

    http://forum.ionicframework.com/t/psa-error-itms-90035-ios-submission-to-app-store/25250/2

    This appears to be a bit of a new error, helpful post though!

  • Jia

    Hi Nic,

    Thanks for the great post. I have few third party js files that I don’t want to minify. Is there any option in cordova uglify to exclude these files from minification (something similar to “externs” in google closure)?

  • Gavin Pickin

    Thanks for this post. I used this Hook a lot, and included it in my presentation recently, and broke it down. Of course I gave you all the credit, and thanks, because of this hook, I’m hooked on Cordova Hooks

    http://www.gpickin.com/index.cfm/blog/cordova-hooks-deep-drive-into-my-js-hint-hook-written-in-nodejs

  • http://buddasworld.co.uk buddaboy

    To get the uglify to work I needed to add –release when doing a build.

    eg.

    ionic build [platform] –release
    cordova build [platform] –release

    Or edit the config file in the hooks folder and set:

    “alwaysRun”: true,

    • Ítalo Ayres

      I’ve tried editing the config file and console showed my files being uglified. But I can’t found the result files anywere, and when I open the developer console with my app running, and look at the source files, they are the originals. Do you know what might be happening?

  • http://nicholls.azurewebsites.net/ Juan David Nicholls
  • http://babbler.eu Raffaele Ianniello

    after I gave the ionic prepare command I get this error:

    module.js:328
    throw err;
    ^

    Error: Cannot find module ‘/Users/networker/Desktop/SostaBlu/node_modules/cordova-uglify/node_modules/uglify-js’
    at Function.Module._resolveFilename (module.js:326:15)
    at Function.Module._load (module.js:277:25)
    at Module.require (module.js:354:17)
    at require (internal/module.js:12:17)
    at Object. (/Users/networker/Desktop/SostaBlu/hooks/after_prepare/uglify.js:11:16)
    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)
    Error: Hook failed with error code 1: /Users/networker/Desktop/SostaBlu/hooks/after_prepare/uglify.js

    • Kasim Sheyi

      Have you been able to resolve this?

      • Kasim Sheyi

        You can solve the issue by opening your project folder then open node modules folder then open cordova-uglify folder then open the node modules folder and copy all the folders you see their then click the back button twice and paste those folders inside node modules folder then build with cordova build [platform] –release.

        Thats the simple trick i used to solve mine

  • Tmpmai Fkmail

    fuck you nic always asking about logs or full logs

  • tao wang

    hi , folder assets/**.js have not minifyied

    E:auth>ionic build android

    Running command: “C:Program Filesnodejsnode.exe” E:authhooksbefore_prepare

    2_jshint.js E:auth

    Linting www/js/app.js

    File www/js/app.js has no errors.

    —————————————–

    Linting www/js/constants.js

    File www/js/constants.js has no errors.

    —————————————–

    Linting www/js/controllers.js

    File www/js/controllers.js has no errors.

    —————————————–

    Linting www/js/services.js

    File www/js/services.js has no errors.

    —————————————–

    Running command: “C:Program Filesnodejsnode.exe” E:authhooksafter_prepare

    010_add_platform_class.js E:auth

    add to body class: platform-android

    Running command: “C:Program Filesnodejsnode.exe” E:authhooksafter_prepare

    uglify.js E:auth

    ANDROID_HOME=C:UsersAdministratorAppDataLocalAndroidsdk1

    JAVA_HOME=C:Program FilesJavajdk1.8.0_65

  • Manish Mourya

    Facing following error. Please check the complete logs. MAC book PRO 10.11.15

    module.js:339
    throw err;
    ^
    Error: Cannot find module ‘mozjpeg-stream’
    at Function.Module._resolveFilename (module.js:337:15)
    at Function.Module._load (module.js:287:25)
    at Module.require (module.js:366:17)
    at require (module.js:385:17)
    at Object. (/**/node_modules/ionic-minify/lib/minifier.js:8:15)
    at Module._compile (module.js:435:26)
    at Object.Module._extensions..js (module.js:442:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:311:12)
    at Module.require (module.js:366:17)
    Error: Hook failed with error code 1: //**//hooks/after_prepare/ionic-minify.js
    at /usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/hooks/HooksRunner.js:195:23
    at _rejected (/usr/local/lib/node_modules/cordova/node_modules/q/q.js:797:24)
    at /usr/local/lib/node_modules/cordova/node_modules/q/q.js:823:30
    at Promise.when (/usr/local/lib/node_modules/cordova/node_modules/q/q.js:1035:31)
    at Promise.promise.promiseDispatch (/usr/local/lib/node_modules/cordova/node_modules/q/q.js:741:41)
    at /usr/local/lib/node_modules/cordova/node_modules/q/q.js:557:44
    at flush (/usr/local/lib/node_modules/cordova/node_modules/q/q.js:108:17)
    at doNTCallback0 (node.js:417:9)
    at process._tickCallback (node.js:346:13)

  • Krishna Karki

    There is an error on the file jshint.js on following code

    console.log(errors[j].line + ‘:’ + errors[j].character + ‘ -> ‘ + errors[j].reason + ‘ -> ‘ +
    errors[j].evidence);

    line, character, evidence variable are not always set so its giving following error to me.

    36:2644 -> Too many errors. (100% scanned). -> undefined
    /Applications/apps/band/hooks/before_prepare/01_jshint.js:65
    console.log(errors[j].line + ‘:’ + errors[j].character + ‘ -> ‘ + errors[j].reason + ‘ -> ‘ +
    ^

    TypeError: Cannot read property ‘line’ of null
    at /Applications/apps/band/hooks/before_prepare/01_jshint.js:65:30
    at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:380:3)

  • Antonio ds

    Change line #8 in after_prepare/uglify.js to:

    var dependencyPath = path.join(cwd, ‘node_modules’);

    Works for me.

  • Francesco Mussi

    Great article! Don’t know how could i lived so far without JSHint

  • William

    When I run this (in vanilla Cordova, not in Ionic) the jshint hook only lints the first of my js files. Any idea why?

    Also, I don’t understand how a value for innercallback in asyc.eachSeries is provided — can you give a bit more detail on that?

    Thanks!

    • William

      Whoops, sorry, I made an edit to the script and that was what was causing the loop to break. Still interested in where innercallback comes from though…

  • Kasim Sheyi

    You can solve the issue by opening your project folder then open node modules folder then open cordova-uglify folder then open the node modules folder and copy all the folders you see their then click the back button twice and paste those folders inside node modules folder then build with cordova build [platform] –release.

    Thats the simple trick i used to solve mine

  • Darshan Tejani

    Great Post Nic. Helped a Lot.
    I was wondering where to put my .jshintrc or JSHint Config file. Can anyone help me with this?

  • Manoj Kumar Mobile App Dept

    I mixed up Progourd and cordova-uglify everything is fine i also want to secure my C:UsersADMINDesktopmyAppwwwbuildmain.js
    By using cordova-uglify code is uglify but by using beatuify js my code main.js is readable how i fix this issue for main.js
    For Progourd
    You need to uncomment below lines from your project.properties file
    To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
    proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt