JQuery issue after upgrade to angular-cli 1.4
- [* ] bug report
Output from: ng --version.
If nothing, output from: node --version and npm --version.
Windows (7/8/10). Linux (incl. distribution). macOS (El Capitan? Sierra?)
node --version
v6.10.3
npm --version 3.10.10
Repro steps.
after upgrading from angular-cli 1.3.0 to 1.4.0 I've got the error: When I load the page: scripts.bundle.js:21 Uncaught TypeError: (intermediate value)(...) is not a function at scripts.bundle.js:21
When I have something which accesses a jquery plugin named waitMe: Create.html:3 ERROR TypeError: jQueryElement.waitMe is not a function at WaitMe.webpackJsonp.../../../../../src/app/core/directives/waitme.directive.ts.WaitMe.startLoadingAnimation (waitme.directive.ts:66) at WaitMe.set [as showWaiting] (waitme.directive.ts:39) at updateProp (core.es5.js:11114) at checkAndUpdateDirectiveInline (core.es5.js:10810) at checkAndUpdateNodeInline (core.es5.js:12349) at checkAndUpdateNode (core.es5.js:12288) at debugCheckAndUpdateNode (core.es5.js:13149) at debugCheckDirectivesFn (core.es5.js:13090) at Object.View_Create_1._co [as updateDirectives] (Create.html:3) at Object.debugUpdateDirectives [as updateDirectives] (core.es5.js:13075)
I've tried installing some versions and for 1.3.2 it works fine, for 1.4.0-rc.0 it doesn't work anymore.
my scripts in angular-cli.json are: "scripts": [ "../node_modules/jquery/dist/jquery.min.js", "../node_modules/wowjs/dist/wow.min.js", "../node_modules/bowser/bowser.min.js", "../src/assets/js/waitme/waitMe.js", "../src/assets/js/html2canvas-0.5.0-beta3/html2canvas.min.js", "../src/assets/js/html2canvas-0.5.0-beta3/js-html2canvas-jquery.plugin.html2canvas.js", "../src/assets/js/jquery.fittext.js" ],
I'm pretty sure that it's related that jQuery can't be found or that it can't convert the waitme jquery plugin anymore. But as I said, when I return to angular-cli 1.3.2 it works again without doing any change.
I have a similar issue, seems like the scripts.bundle.js.map file is missing with 1.4.0 with 1.3.2 the file is created
I have the same issue for now I pinned @angular/cli version to 1.3.2 and works for me.
I have the same problem... 😢
Heya, I'd like to investigate and fix this. Can someone provide me with a simple reproduction (a project made with ng new and the least amount of changes possible to see the problem)?
When we test for script order everything seems fine, but our test must be missing something and the quickest way to fix it is to have a repro from an affected user.
Hi, I was using angular2 to build a site, then we decide to start using angular-cli for the project and re-build same component/modules in the new one, I am facing issue to use similar libraries (JQuery & JQuery.ui & toastr ... ) just to name few. in previous project based on angular2, I used to update "systemjs.config.js" with these packages, after install them from npm. now with angular-cli, I have installed the packages under "node_modules/@types/" folder and then updated tsconfig.json with the types names as below "types": [ "jquery", "jqueryui", "toastr", "tether" ] I am still not able to see these packages after run "ng serve" command under node_modules library on the browser. Can you please help me figure out what wrong and how to fix it. Thanks
Hey guys, because you referred to script order, I tried the following, I rearranged my scripts in angular-cli from: "scripts": [ "../node_modules/jquery/dist/jquery.min.js", "../node_modules/wowjs/dist/wow.min.js", "../node_modules/bowser/bowser.min.js", "../src/assets/js/waitme/waitMe.js", "../src/assets/js/html2canvas-0.5.0-beta3/html2canvas.min.js", "../src/assets/js/html2canvas-0.5.0-beta3/js-html2canvas-jquery.plugin.html2canvas.js", "../src/assets/js/jquery.fittext.js" ],
to:
"scripts": [
"../node_modules/wowjs/dist/wow.min.js",
"../node_modules/bowser/bowser.min.js",
"../src/assets/js/html2canvas-0.5.0-beta3/html2canvas.min.js",
"../node_modules/jquery/dist/jquery.min.js",
"../src/assets/js/waitme/waitMe.js",
"../src/assets/js/html2canvas-0.5.0-beta3/js-html2canvas-jquery.plugin.html2canvas.js",
"../src/assets/js/jquery.fittext.js"
],
and this solved my issue.
i dont understand, why jquery not first in your script
@filipesilva We have a similar issue on the Angular repo:
https://github.com/angular/angular/issues/20425
Reproduction repo link available in that issue.
@DanijelJurjevic I tried to follow the reproduction you provided in https://github.com/angular/angular/issues/20425 and I think I've found the problem in it.
You load two scripts: ./assets/jquery.min.js and ./assets/test.js. The test.js script contains the following:
$("#changeText").click(function() {
alert("it works");
});
This registers a click handler on the element with changeText id.
If you check the script order in index.html (during ng serve) you can see that scripts.bundle.js is loaded before your app (main.bundle.js):
<script type="text/javascript" src="inline.bundle.js"></script>
<script type="text/javascript" src="polyfills.bundle.js"></script>
<script type="text/javascript" src="scripts.bundle.js"></script>
<script type="text/javascript" src="styles.bundle.js"></script>
<script type="text/javascript" src="vendor.bundle.js"></script>
<script type="text/javascript" src="main.bundle.js"></script></body>
So when your script runs, the app is not running yet. Since the app is not running, there is no element with the changeText id. Single Page Applications generate html while running, so you cannot bind handlers to those elements before they are there.
Changing routes should also not re-run any scripts. They should only run when the page is loaded the first time.
So if you need to register any JQuery handlers for components, you will need to do it after the component is instantiated. But then it will be much better to just use Angular bindings instead.
To the other users reporting problems with scripts, please provide a reproduction. Without a reproduction I cannot investigate this problem.
Closing as no reproduction was provided.
This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.