Update jquery version without linking to an external file

I recently ran into a problem when trying to upload multiple images and when I tried to implement the solution suggested my IDE (phpStorm 2017.1.4) detects it as an error saying "let definitions are not supported by current JavaScript version".

7412

let.png

When I checked in vendor/bower/jquery/dist/jquery.js the current version is 2.2.4. I ran a composer update but it doesn’t update to a 3.* version (currently lastest version is 3.2.1).

I was wandering how could I update my jQuery version? Would I have to link it like an external library in the appAsset file or could the bower/jquery version be updated? Hopefully this would solve my original problem of using the let statement in a for loop. Would appreciate any suggestions.

Thanks

JavaScript and jQuery are not the same thing and a lot of people seem to confuse the two like you have. jQuery is just a library to make using JavaScript easier. With that said, let is part of ECMAScript 6/ES6/es2015 the new flavor of JavaScript.

You need to update your IDE since it’s an IDE error to a version that supports es6.

Well like i said I’m using the IDE phpStorm 2017.1.4 (which was updated around April this year I think) so seems strange that they wouldn’t support es6 if it is a standard that was implemented in 2015 which is why I started looking for the libraries installed in my project. Still when I try out my code in a browser that does support es6 (Mozilla firefox 54) I don’t get the expected result from using the ‘let’ statement which should let me use the value of i in an iteration (or at least that is what I understood).

On the other hand I get that JavaScript and jQuery are not the same thing. Still, now I am interested in knowing how I could update my jQuery version to 3.2.1 from the current 2.2.4 version without loading 2 different jQuery files in my assets.

I don’t use PhpStorm, so I can’t say for sure. It either doesn’t support ES2015 or you have the option somewhere of setting what the version of JavaScript you plan to use; ES2015 (formerly ES6) or ES5.

That said, I wouldn’t recommend fully relying on ES2015. I know in some relatively version of Blink/Webkit browsers there were some conflicts where Chrome required “let” and “const” to be used in a strict setting while Safari complained about that. You should Babel/transpile your files back to ES5. Then you can leverage ES2016 and ES2017 as well and Babel will make that backwards compatible to ES5.

Looking at installed packages it looks like jQuery is in the "bower" directory. You will have to install jQuery yourself and use that file instead.

Set your jquery in your main config file




'components' => [

 'assetManager' => [

  'class' => 'yii\web\AssetManager',

  'bundles' => [

   'yii\web\JqueryAsset' => [

    'js' => [

 	'path_to_your_jquery.min.js'

 	]

   ]

  ]

 ]

]