【问题标题】:vuejs webpack relative modules were not found errorvuejs webpack相关模块未找到错误
【发布时间】:2017-12-17 01:19:04
【问题描述】:

我有全栈应用程序,带有 express 和默认 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

有什么建议吗?

【问题讨论】:

    标签: npm webpack vue.js vuejs2


    【解决方案1】:

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

    【讨论】:

    • 这个答案不清楚。您能否发布问题的确切解决方案?你采取了哪些措施来解决它?
    • 对我来说,这是通过在 webpack 配置中添加以下内容来解决的: context: __dirname 根据您的设置,您可能需要类似 context: path.join(__dirname, '../')跨度>
    猜你喜欢
    • 2019-01-15
    • 1970-01-01
    • 1970-01-01
    • 2017-03-22
    • 2018-08-05
    • 2016-07-23
    • 2015-06-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多