前端开发:遇到This relative module was not found 的解决方法

简介: 在前端开发的时候,会遇到因为引入的文件路径不正确而造成的报错问题,这类问题在前端开发过程中很常见,但是还是会遇到不少坑。那么本文就来分享一个关于在前端开发过程中遇到This relative module was not found 的报错的解决方法。

前言

在前端开发的时候,会遇到因为引入的文件路径不正确而造成的报错问题,这类问题在前端开发过程中很常见,但是还是会遇到不少坑。那么本文就来分享一个关于在前端开发过程中遇到This relative module was not found 的报错的解决方法。

报错提示

ERROR  Failed to compile with 1 errors                                                                                                              上午10:55:30
This relative module was not found:
* ../assets/images/icon_tips.png in ./node_modules/vue-loader/lib/template-compiler?{"id":"data-v-b98493b6","hasScoped":true,"transformToRequire":{"video":"src","source":"src","img":"src","image":"xlink:href"},"buble":{"transforms":{}}}!./node_modules/vue-loader/lib/selector.js?type=template&index=0!./src/components/Popover.vue

报错原因

本案例的报错是因为引入图片的路径没有写对,造成找不到图片。其他的同款错误可能是文件中引入图片出现问题,路径错误或者文件不存在,类似问题也是如此,所以在开发中遇到类似的报错直接排查路径即可解决问题。具体的示例解决方法如下所示。

解决方法

先来看一下报错之时的写法,具体如下所示:

1、原始代码写法

<span
    v-if="content"
    ref="popover"
    data-toggle="popover"
    data-placement="top"
    data-trigger="click"
    role="button"
    data-container="body"
    @touchstart="onTouchstart"
  >
    <slot name="reference" @click="onClick">
      <van-icon :name="require('../assets/images/icon_tips.png')" />
    </slot>
  </span>

对比错误排查之后,修改有问题的代码之后的写法,具体如下所示。

2、修改后的代码写法

<span
    v-if="content"
    ref="popover"
    data-toggle="popover"
    data-placement="top"
    data-trigger="click"
    role="button"
    data-container="body"
    @touchstart="onTouchstart"
  >
    <slot name="reference" @click="onClick">
      <van-icon :name="require('../assets/image/icon_tips.png')" />
    </slot>
  </span>

经过对报错地方的排查,修改报错的地方之后,重新运行项目,报错问题就解决了。

最后

通过上面介绍的关于在前端开发过程中遇到This relative module was not found 的解决方法,往后再在前端开发中遇到类似报错问题就可以很好的解决了,这里不再赘述。以上就是本章的全部内容,欢迎关注三掌柜的微信公众号“程序猿by三掌柜”,三掌柜的新浪微博“三掌柜666”,欢迎关注!

相关文章
|
8月前
|
JavaScript
Syntax Error: Error: Cannot find module ‘node-sass‘
Syntax Error: Error: Cannot find module ‘node-sass‘
167 0
|
2月前
|
资源调度 前端开发
编译第三方前端项目时候出现Syntax Error: TypeError: Cannot set properties of undefined (setting ‘parent‘)
编译第三方前端项目时候出现Syntax Error: TypeError: Cannot set properties of undefined (setting ‘parent‘)
127 0
|
2月前
报错/ ./node_modules/axios/lib/platform/index.js Module parse failed: Unexpected token (5:2)怎么解决?
报错/ ./node_modules/axios/lib/platform/index.js Module parse failed: Unexpected token (5:2)怎么解决?
|
2月前
vue2项目安装出现Syntax Error: Error: Cannot find module ‘less‘
vue2项目安装出现Syntax Error: Error: Cannot find module ‘less‘
17 0
|
8月前
|
JavaScript
vue踩坑-This relative module was not found
vue踩坑-This relative module was not found
112 0
|
7月前
|
JavaScript
Vue项目报错:This relative module was not found
Vue项目报错:This relative module was not found
|
7月前
|
前端开发 JavaScript
Module build failed: TypeError: this.getResolve is not a function,vue写css时启动出错
Module build failed: TypeError: this.getResolve is not a function,vue写css时启动出错
25 0
|
11月前
|
前端开发 JavaScript
解决前端报错 Error: Cannot find module ‘xxx‘(包含 uniapp)
解决前端报错 Error: Cannot find module ‘xxx‘(包含 uniapp)
542 0
|
12月前
打包报错Error: ‘default‘ is not exported by node_modules/qs/lib/index.js
打包报错Error: ‘default‘ is not exported by node_modules/qs/lib/index.js
223 0
|
12月前
|
数据采集 前端开发 测试技术
React项目中Manifest: Line: 1, column: 1, Syntax error的解决方法
大家好,今天和大家分享一个React项目中的一个小报错的解决方法。 在创建了一个项目后会有几个文件