简体   繁体   中英

Bower throws jquery “not injected” warning after running grunt serve

I've recently had to clone an project and rebuild bower packages. jQuery has updated I believe, and is now throwning an warning:

Warning:
Please go take a look in "app/bower_components/jquery" for the file you need, then manually include it in your file.

I've done this. And everythign works properly. However, everytime I grunt serve the warning still gets thrown?

jquery was not injected in your file.

How do I remove this error? and will this error out a grunt build? I'm sure the warning is harmless but it's really upsetting to keep seeing it.

main .bower.json

{
  "name": "jordan",
  "version": "0.0.0",
  "dependencies": {
    "angular": "1.2.6",
    "json3": "~3.2.6",
    "es5-shim": "~2.1.0",
    "angular-resource": "1.2.6",
    "angular-cookies": "1.2.6",
    "angular-sanitize": "1.2.6",
    "angular-route": "1.2.6",
    "jquery-ui": "~1.10.3"
  },
  "devDependencies": {
    "angular-mocks": "1.2.6",
    "angular-scenario": "1.2.6"
  }
}

在此输入图像描述

.bower.json for jquery

{
  "name": "jquery",
  "version": "2.1.0",
  "ignore": [
    "**/.*",
    "build",
    "speed",
    "test",
    "*.md",
    "AUTHORS.txt",
    "Gruntfile.js",
    "package.json",
    "bower.json"
  ],
  "dependencies": {
    "sizzle": "1.10.16"
  },
  "devDependencies": {
    "requirejs": "~2.1.8",
    "qunit": "~1.12.0",
    "sinon": "~1.7.3"
  },
  "keywords": [
    "jquery",
    "javascript",
    "library"
  ],
  "homepage": "https://github.com/jquery/jquery",
  "_release": "2.1.0",
  "_resolution": {
    "type": "version",
    "tag": "2.1.0",
    "commit": "cac43f3ef791b7e68c1917a734fb92e04450c111"
  },
  "_source": "git://github.com/jquery/jquery.git",
  "_target": ">=1.6",
  "_originalSource": "jquery"
}

You can workaround this problem changing the bower.json of your project and override some package with problem

"overrides": {
  "jquery": {
    "main": "./dist/jquery.js"
  }
}

You can sse more about that in https://github.com/bower/bower/issues/585

But, looks like that current version of the JQuery is playing into the Bower rules.

As explained on the related Github issues available here: https://github.com/stephenplusplus/grunt-bower-install/issues/55

This isn't an error with grunt-bower-install - this is, sadly, jQuery not playing by Bower's rules. It's not possible for this tool to work with a Bower package that doesn't specify main property. Like any other package that doesn't, the solution is to manually include the reference to the file inside of your HTML file, like the good ol' days

I'm sorry man, I had the same problem just now :(

In general, if you get this error it is because the author of whatever bower component you are using either hasn't included a bower.json file in the component or hasn't define a "main" property in the bower.json folder. If the component is being actively maintained, you should open a github issue asking for a proper bower.json file in the component. Here is an real world example...

https://github.com/CreateJS/SoundJS/issues/76

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM