vue项目开启webpack modules为什么会报错?

webpack中配置modules后页面报错没安装依赖,但是这些依赖我都已经安装了,package.json中有配置信息。

报错信息如下:

These dependencies were not found:

* ansi-html in (webpack)-dev-server/client/overlay.js
* axios in ./src/main.js
* html-entities in (webpack)-dev-server/client/overlay.js
* lodash in ./node_modules/babel-loader/lib!./node_modules/vue-loader/lib/selector.js?type=script&index=0!./src/components/lodash.vue
* loglevel in (webpack)-dev-server/client?http://localhost:8080
* sockjs-client/dist/sockjs in (webpack)-dev-server/client/socket.js
* strip-ansi in (webpack)-dev-server/client?http://localhost:8080
* vue in ./src/App.vue, ./src/main.js and 5 others
* vue-hot-reload-api in ./src/App.vue, ./node_modules/vue-loader/lib/template-compiler?{"id":"data-v-7ba5bd90","hasScoped":false,"transformToRequire":{"video":["src","poster"],"source":"src","img":"src","image":"xlink:href"},"buble":{"transforms":{}}}!./node_modules/vue-loader/lib/selector.js?type=template&index=0!./src/App.vue and 8 others
* vue-router in ./src/router/index.js
* webpack/hot in (webpack)-dev-server/client?http://localhost:8080
* webpack/hot/dev-server in multi (webpack)-dev-server/client?http://localhost:8080 webpack/hot/dev-server ./src/main.js
* webpack/hot/emitter in (webpack)-dev-server/client?http://localhost:8080

To install them, you can run: npm install --save ansi-html axios html-entities lodash loglevel sockjs-client/dist/sockjs strip-ansi vue vue-hot-reload-api vue-router webpack/hot webpack/hot/dev-server webpack/hot/emitter

添加的webpack配置如下:

resolve: {
    modules: ['src', 'src/components'].map(resolve)
}

把这段modules配置去掉就不报错了。

阅读 4.7k
1 个回答

加上node_modules

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题