未找到 Sass 相关模块?
Posted
技术标签:
【中文标题】未找到 Sass 相关模块?【英文标题】:Sass relative modules not found? 【发布时间】:2020-04-24 13:23:24 【问题描述】:当在我的 Vue 组件 <style>
标签中包含一个 Sass 文件(在 node_modules
中)时,该文件被定位,但该文件的任何相关模块都不是。一切似乎都配置正确,但我显然遗漏了一些东西。什么给了?
我尝试安装/卸载各种 Webpack 加载器(包括 css-loader
),删除并重新安装 node_modules
,尝试了各种 PostCSS 配置,但到目前为止没有任何进展。
提前致谢。
Vue 组件(IconicIcon.vue
):
<template>
<div>
<span class="oi oi-icon-name" :title="icon" aria-hidden="true"></span>
</div>
</template>
<script>
export default
name: "iconic-icon",
props:
icon: String
;
</script>
<style scoped lang="scss">
$icon-font-path: "~open-iconic/font/css/fonts";
@import "~open-iconic/font/css/open-iconic-bootstrap.scss";
</style>
open-iconic-bootstrap.scss
:
/* Bootstrap */
/* Override Bootstrap default variable */
$icon-font-path: '../fonts/' !default;
@font-face
font-family: 'Icons';
src: url('#$icon-font-pathopen-iconic.eot');
src: url('#$icon-font-pathopen-iconic.eot?#iconic-sm') format('embedded-opentype'), url('#$icon-font-pathopen-iconic.woff') format('woff'), url('#$icon-font-pathopen-iconic.ttf') format('truetype'), url('#$icon-font-pathopen-iconic.svg#iconic-sm') format('svg');
font-weight: normal;
font-style: normal;
... (snip)
相关文件结构:
root/
src/
components/
IconicIcon.vue
node_modules/
open-iconic/
font/
css/
open-iconic-bootstrap.scss
fonts/
open-iconic.eot
open-iconic.otf
open-iconic.svg
open-iconic.ttf
open-iconic.woff
错误:
WAIT Compiling... 8:37:49 PM
98% after emitting CopyPlugin
ERROR Failed to compile with 4 errors 8:37:50 PM
These relative modules were not found:
* ../fonts/open-iconic.eot in ./node_modules/css-loader/dist/cjs.js??ref--8-oneOf-1-1!./node_modules/vue-loader/lib/loaders/stylePost
Loader.js!./node_modules/postcss-loader/src??ref--8-oneOf-1-2!./node_modules/sass-loader/dist/cjs.js??ref--8-oneOf-1-3!./node_modules
/cache-loader/dist/cjs.js??ref--0-0!./node_modules/vue-loader/lib??vue-loader-options!./src/components/IconicIcon.vue?vue&type=style&
index=0&id=468ee29c&scoped=true&lang=scss&
* ../fonts/open-iconic.svg in ./node_modules/css-loader/dist/cjs.js??ref--8-oneOf-1-1!./node_modules/vue-loader/lib/loaders/stylePost
Loader.js!./node_modules/postcss-loader/src??ref--8-oneOf-1-2!./node_modules/sass-loader/dist/cjs.js??ref--8-oneOf-1-3!./node_modules
/cache-loader/dist/cjs.js??ref--0-0!./node_modules/vue-loader/lib??vue-loader-options!./src/components/IconicIcon.vue?vue&type=style&
index=0&id=468ee29c&scoped=true&lang=scss&
* ../fonts/open-iconic.ttf in ./node_modules/css-loader/dist/cjs.js??ref--8-oneOf-1-1!./node_modules/vue-loader/lib/loaders/stylePost
Loader.js!./node_modules/postcss-loader/src??ref--8-oneOf-1-2!./node_modules/sass-loader/dist/cjs.js??ref--8-oneOf-1-3!./node_modules
/cache-loader/dist/cjs.js??ref--0-0!./node_modules/vue-loader/lib??vue-loader-options!./src/components/IconicIcon.vue?vue&type=style&
index=0&id=468ee29c&scoped=true&lang=scss&
* ../fonts/open-iconic.woff in ./node_modules/css-loader/dist/cjs.js??ref--8-oneOf-1-1!./node_modules/vue-loader/lib/loaders/stylePos
tLoader.js!./node_modules/postcss-loader/src??ref--8-oneOf-1-2!./node_modules/sass-loader/dist/cjs.js??ref--8-oneOf-1-3!./node_module
s/cache-loader/dist/cjs.js??ref--0-0!./node_modules/vue-loader/lib??vue-loader-options!./src/components/IconicIcon.vue?vue&type=style
&index=0&id=468ee29c&scoped=true&lang=scss&
package.json
:
"name": "myapp",
"version": "0.1.0",
"private": true,
"scripts":
"dev": "concurrently -r -k -n doc,nod,vue -c magenta,green,cyan \"docker-compose up\" \"nodemon server/app.js\" \"vue-cli-service serve\"",
"build": "vue-cli-service build",
"start": "node server/app.js",
"test:unit": "vue-cli-service test:unit",
"test:e2e": "vue-cli-service test:e2e"
,
"dependencies":
"apollo-server": "^2.9.15",
"babel-loader": "^8.0.6",
"bootstrap": "^4.4.1",
"core-js": "^3.4.3",
"eslint": "^6.8.0",
"graphql": "^14.5.8",
"graphql-type-json": "^0.2.1",
"jquery": "^3.4.1",
"js-yaml-loader": "^1.2.2",
"leaflet": "^1.6.0",
"lowdb": "^1.0.0",
"mkdirp": "^0.5.1",
"mongodb": "^3.4.1",
"open-iconic": "^1.1.1",
"popper.js": "^1.16.0",
"shortid": "^2.2.8",
"slugify": "^1.3.6",
"vue": "^2.6.10",
"vue-router": "^3.1.3",
"vuex": "^3.1.2"
,
"devDependencies":
"@vue/cli-plugin-babel": "^4.1.0",
"@vue/cli-plugin-e2e-cypress": "^4.1.0",
"@vue/cli-plugin-router": "^4.1.0",
"@vue/cli-plugin-unit-jest": "^4.1.0",
"@vue/cli-plugin-vuex": "^4.1.0",
"@vue/cli-service": "^4.1.0",
"@vue/test-utils": "1.0.0-beta.29",
"concurrently": "^5.0.2",
"graphql-tag": "^2.9.0",
"node-sass": "^4.12.0",
"sass-loader": "^8.0.0",
"vue-template-compiler": "^2.6.10"
,
"browserslist": [
"> 1%",
"last 2 versions"
],
"jest":
"preset": "@vue/cli-plugin-unit-jest"
【问题讨论】:
我认为这可能对github.com/vuejs-templates/webpack/issues/1313有帮助。 感谢@User28。我检查了那个线程;似乎它应该有所帮助,但不幸的是它还没有。更新<script>
中字体的默认位置是有意义的。但是,我还没有弄清楚如何正确修改vue.config.js
。也许我会弃用并只使用 Font Awesome,因为它似乎对那些家伙有用。 :(
【参考方案1】:
我只使用 CSS 而不是 Sass 解决了这个问题。看起来像个逃避现实,但我已经在这上面花了太多时间了。
<template>
<div>
<span class="oi" :title="icon" aria-hidden="true" :class="`oi-$icon`"></span>
</div>
</template>
<script>
export default
name: "iconic-icon",
props:
icon: String
;
</script>
<style scoped lang="scss">
@import "~open-iconic/font/css/open-iconic-bootstrap.css";
</style>
【讨论】:
【参考方案2】:此类问题可能与 saas 加载程序的工作方式有关。 我在我的一个项目中遇到了同样的问题,并通过将字体目录移动到 assets 文件夹来解决它。
如果你用谷歌搜索这个,你会发现other found the same solution 我在这里发帖。
在您的情况下,您应该将 $icon-font-path 变量更改为以下内容: $icon-font-path: '/assets/fonts/' !default;
它会起作用的!
【讨论】:
以上是关于未找到 Sass 相关模块?的主要内容,如果未能解决你的问题,请参考以下文章
我制作的 vue 前端编译失败,出现一个错误,提示“未找到此相关模块模块”
无法制作模块:未找到相关的gradle配置。请重新导入 Gradle 项目并重试
错误('`libsass` 未找到绑定。尝试使用运行 ionic 的 node-sass 重新安装 `node-sass`?')