vuejs webpack相关模块未找到错误

时间:2017-07-12 14:32:20

标签: npm webpack vue.js vuejs2

我有使用express和default vue-webpack-boilerplate的全栈应用程序。 我的项目结构如下所示:

├── client
│   ├── build
│   │   └── ...
│   ├── config
│   │   └── ...
│   ├── dist
|   |   └── ...
│   ├── index.html
│   ├── src
│   │   ├── App.vue
│   │   ├── assets
│   │   │   └── ...
│   │   ├── components
│   │   │   └── ...
│   │   ├── main.js
│   │   └── router
│   └── static
├── node_modules
├── package.json
└── server
    ├── app.js
    ├── bin
    │   └── www
    └── routes
        └── ...

当我运行$ node client/build/dev-server.js时,我收到此错误:

ERROR  Failed to compile with 2 errors

These relative modules were not found:

* ./build/dev-client in multi ./build/dev-client ./src/main.js
* ./src/main.js in multi ./build/dev-client ./src/main.js

但是只有当我尝试从客户端文件夹运行它才能正常工作。

$ cd client 
$ node build/dev-server.js

有什么建议吗?

2 个答案:

答案 0 :(得分:3)

这是相对路径的错误。您需要更改相对于新根文件夹而不是客户端文件夹的require()中使用的所有路径。良好做法是使用与__dirname方法相同的path.diranme()。检查this

答案 1 :(得分:-3)

我通过更新所有npm包来解决它: npm i -g npm-check-updates npm-check-updates -u npm install

请在执行上述操作之前提交package.json