运行时报错,关乎依赖问题:These dependencies were not found

来源:3-2 路由配置+ tab 顶导组件开发

半晴雨滴

2018-04-03

{
  "name": "vue-music",
  "version": "1.0.0",
  "description": "Music player",
  "author": "Jason <jsonwu@qq.com>",
  "private": true,
  "scripts": {
    "dev": "node build/dev-server.js",
    "start": "node build/dev-server.js",
    "build": "node build/build.js",
    "lint": "eslint --ext .js,.vue src"
  },
  "dependencies": {
    "babel-runtime": "^6.0.0",
    "vue": "^2.2.6",
    "vue-router": "^2.3.1",
    "fastclick": "^1.0.6",
    "vue-lazyload": "1.0.3",
    "axios": "^0.16.1",
    "jsonp": "0.2.1",
    "better-scroll": "^0.1.15"
  },
  "devDependencies": {
    "autoprefixer": "^6.7.2",
    "babel-core": "^6.22.1",
    "babel-eslint": "^7.1.1",
    "babel-loader": "^6.2.10",
    "babel-plugin-transform-runtime": "^6.22.0",
    "babel-preset-env": "^1.3.2",
    "babel-preset-stage-2": "^6.22.0",
    "babel-register": "^6.22.0",
    "babel-polyfill": "^6.2.0",
    "chalk": "^1.1.3",
    "connect-history-api-fallback": "^1.3.0",
    "copy-webpack-plugin": "^4.0.1",
    "css-loader": "^0.28.0",
    "eslint": "^3.19.0",
    "eslint-friendly-formatter": "^2.0.7",
    "eslint-loader": "^1.7.1",
    "eslint-plugin-html": "^2.0.0",
    "eslint-config-standard": "^6.2.1",
    "eslint-plugin-promise": "^3.4.0",
    "eslint-plugin-standard": "^2.0.1",
    "eventsource-polyfill": "^0.9.6",
    "express": "^4.14.1",
    "extract-text-webpack-plugin": "^2.0.0",
    "file-loader": "^0.11.1",
    "friendly-errors-webpack-plugin": "^1.1.3",
    "html-webpack-plugin": "^2.28.0",
    "http-proxy-middleware": "^0.17.3",
    "webpack-bundle-analyzer": "^2.2.1",
    "semver": "^5.3.0",
    "shelljs": "^0.7.6",
    "opn": "^4.0.2",
    "optimize-css-assets-webpack-plugin": "^1.3.0",
    "ora": "^1.2.0",
    "rimraf": "^2.6.0",
    "url-loader": "^0.5.8",
    "vue-loader": "^11.3.4",
    "vue-style-loader": "^2.0.5",
    "vue-template-compiler": "^2.2.6",
    "webpack": "^2.3.3",
    "webpack-dev-middleware": "^1.10.0",
    "webpack-hot-middleware": "^2.18.0",
    "webpack-merge": "^4.1.0",
    "stylus": "^0.54.5",
    "stylus-loader": "^2.1.1"
  },
  "engines": {
    "node": ">= 4.0.0",
    "npm": ">= 3.0.0"
  },
  "browserslist": [
    "> 1%",
    "last 2 versions",
    "not ie <= 8"
  ]
}

这是package.json,已经参考了老师源码,但是运行时还是报错:

ERROR  Failed to compile with 5 errors                                                                                                                                                                                      10:08:58

These dependencies were not found:

* api/recommend in ./~/babel-loader/lib!./~/vue-loader/lib/selector.js?type=script&index=0!./src/components/recommend/recommend.vue
* api/config in ./~/babel-loader/lib!./~/vue-loader/lib/selector.js?type=script&index=0!./src/components/recommend/recommend.vue
* base/slider/slider in ./~/babel-loader/lib!./~/vue-loader/lib/selector.js?type=script&index=0!./src/components/recommend/recommend.vue
* base/loading/loading in ./~/babel-loader/lib!./~/vue-loader/lib/selector.js?type=script&index=0!./src/components/recommend/recommend.vue
* base/scroll/scroll in ./~/babel-loader/lib!./~/vue-loader/lib/selector.js?type=script&index=0!./src/components/recommend/recommend.vue

To install them, you can run: npm install --save api/recommend api/config base/slider/slider base/loading/loading base/scroll/scroll

按照提示去安装依赖,结果又报错提示:

npm ERR! code ENOLOCAL
npm ERR! Could not install from "base\slider\slider" as it does not contain a package.json file.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\F1332441\AppData\Roaming\npm-cache\_logs\2018-04-03T02_38_38_300Z-debug.log

请问老师,这要怎样解决?

写回答

4回答

ustbhuangyi

2018-04-03

显然你要在 package.json 里添加 better-scroll、 axios 这些依赖库啊

1
1
半晴雨滴
非常感谢!
2018-04-03
共1条回复

半晴雨滴

提问者

2018-04-03

找到原因了, 我的 package.json 里是有添加 better-scroll、 axios 这些依赖库的,但是执行 npm install 不知道为什么就这几个依赖库一直没有安装上,多安装了几次然后才安装上,可能是因为网络原因吧。后面遇到这问题的同学可以换 淘宝的 cnpm 试试。另外,感谢老师的解答!

1
0

ustbhuangyi

2018-04-03

你有配置 api、base 这些的 alias 吗

1
0

半晴雨滴

提问者

2018-04-03

resolve: {
  extensions: ['.js', '.vue', '.json'],
  alias: {
    '@': resolve('src'),
    'common': resolve('src/common'),
    'components': resolve('src/components'),
    'base': resolve('src/base'),
    'api': resolve('src/api')
  }
},

这要配置,然后再运行还是报错。

 ERROR  Failed to compile with 4 errors                                                                                                                                                                                      11:35:09

These dependencies were not found:

* axios in ./src/api/recommend.js
* better-scroll in ./~/babel-loader/lib!./~/vue-loader/lib/selector.js?type=script&index=0!./src/base/slider/slider.vue, ./~/babel-loader/lib!./~/vue-loader/lib/selector.js?type=script&index=0!./src/base/scroll/scroll.vue
* jsonp in ./src/common/js/jsonp.js

To install them, you can run: npm install --save axios better-scroll jsonp

试过删掉所有插件再重新 npm install后运行还是这样报错。

我跟着视频一步步来的,但是视频里面有些地方要加哪些文件没有说明白诶,对比源码才知道少了哪些文件,不过有些文件有变动的话对比起来很麻烦,请问老师有每个章节未完成的源码吗?就是每个章节视频开始的时候的素材。

0
0

Vue2.0高级应用教学实战,开发企业级移动端音乐Web App

Vue.js高级知识应用大集合,实战企业级APP,教你搞定组件化开发。

5432 学习 · 3804 问题

查看课程