vuejs webpack相关模块未找到错误

Leo*_*und 5 npm webpack vue.js vuejs2

我有快速和默认的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
        ??? ...
Run Code Online (Sandbox Code Playgroud)

当我运行时,$ 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
Run Code Online (Sandbox Code Playgroud)

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

$ cd client 
$ node build/dev-server.js
Run Code Online (Sandbox Code Playgroud)

有什么建议?

Leo*_*und 4

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

  • 这个答案并不清楚。您能发布问题的确切解决方案吗?你采取了什么步骤来解决它? (15认同)