仔仔_iZaiZaiA
仔仔_iZaiZaiA
  • 发布:2023-03-10 11:55
  • 更新:2023-09-16 13:08
  • 阅读:1112

【报Bug】 vue3 + vite下,使用 uni-scss,报错

分类:uni-app

产品分类: uniapp/H5

PC开发环境操作系统: Mac

PC开发环境操作系统版本号: macOS 13.2.1 (M1芯片)

HBuilderX类型: 正式

HBuilderX版本号: 3.7.3

浏览器平台: Edge

浏览器版本: 110.0.1587.63

项目创建方式: HBuilderX

操作步骤:
<style lang="scss">  
@import '@/uni_modules/uni-scss';  

</style>

预期结果:

正常可用,不报错

实际结果:
11:48:40.501 hmr update /App.vue?vue&type=style&index=0&lang.scss  
11:48:40.590 /Applications/HBuilderX.app/Contents/HBuilderX/plugins/uniapp-cli-vite/node_modules/resolve/lib/sync.js:111  
11:48:40.595     var err = new Error("Cannot find module '" + x + "' from '" + parent + "'");  
11:48:40.595               ^  
11:48:40.601 Error: Cannot find module '/Users/uniappTest/uni_modules/uni-scss' from '/Users/uniappTest/App.vue'  
11:48:40.605     at resolveSync (/Applications/HBuilderX.app/Contents/HBuilderX/plugins/uniapp-cli-vite/node_modules/resolve/lib/sync.js:111:15)  
11:48:40.610     at Function.resolve_1.default.sync (/Applications/HBuilderX.app/Contents/HBuilderX/plugins/uniapp-cli-vite/node_modules/@dcloudio/uni-cli-shared/dist/hbx/alias.js:46:20)  
11:48:40.610     at resolveWithSymlinks (/Applications/HBuilderX.app/Contents/HBuilderX/plugins/uniapp-cli-vite/node_modules/@dcloudio/uni-cli-shared/dist/resolve.js:20:30)  
11:48:40.614     at requireResolve (/Applications/HBuilderX.app/Contents/HBuilderX/plugins/uniapp-cli-vite/node_modules/@dcloudio/uni-cli-shared/dist/resolve.js:16:12)  
11:48:40.618     at Context.customResolver (/Applications/HBuilderX.app/Contents/HBuilderX/plugins/uniapp-cli-vite/node_modules/@dcloudio/vite-plugin-uni/dist/config/resolve.js:28:48)  
11:48:40.622     at Context.resolveId (file:///Applications/HBuilderX.app/Contents/HBuilderX/plugins/uniapp-cli-vite/node_modules/vite/dist/node/chunks/dep-5e7f419b.js:221:54)  
11:48:40.622     at Object.resolveId (file:///Applications/HBuilderX.app/Contents/HBuilderX/plugins/uniapp-cli-vite/node_modules/vite/dist/node/chunks/dep-5e7f419b.js:41433:46)  
11:48:40.626     at Object.<anonymous> (file:///Applications/HBuilderX.app/Contents/HBuilderX/plugins/uniapp-cli-vite/node_modules/vite/dist/node/chunks/dep-5e7f419b.js:61735:37)  
11:48:40.630     at Object.internalImporter (file:///Applications/HBuilderX.app/Contents/HBuilderX/plugins/uniapp-cli-vite/node_modules/vite/dist/node/chunks/dep-5e7f419b.js:36967:19)  
11:48:40.633     at JavaScriptObject.apply$2 (/Applications/HBuilderX.app/Contents/HBuilderX/plugins/compile-dart-sass/node_modules/sass/sass.dart.js:23739:23) {  
11:48:40.633   code: 'MODULE_NOT_FOUND'  
11:48:40.637 }

bug描述:

根据官方文档,使用类名 ,我在我的vue3 + vite 的uni-app项目里的App.vue里,

按照教程写

<style lang="scss">  
@import '@/uni_modules/uni-scss';  

</style>

然后报错了。。。。


uni_modules里组件是存在的,在uni.scss里引入 variables.scss,都没问题。

/* 需要放到文件最上面 */  
@import '@/uni_modules/uni-scss/variables.scss';

uni-scss 报错内容:

11:48:40.501 hmr update /App.vue?vue&type=style&index=0&lang.scss  
11:48:40.590 /Applications/HBuilderX.app/Contents/HBuilderX/plugins/uniapp-cli-vite/node_modules/resolve/lib/sync.js:111  
11:48:40.595     var err = new Error("Cannot find module '" + x + "' from '" + parent + "'");  
11:48:40.595               ^  
11:48:40.601 Error: Cannot find module '/Users/uniappTest/uni_modules/uni-scss' from '/Users/uniappTest/App.vue'  
11:48:40.605     at resolveSync (/Applications/HBuilderX.app/Contents/HBuilderX/plugins/uniapp-cli-vite/node_modules/resolve/lib/sync.js:111:15)  
11:48:40.610     at Function.resolve_1.default.sync (/Applications/HBuilderX.app/Contents/HBuilderX/plugins/uniapp-cli-vite/node_modules/@dcloudio/uni-cli-shared/dist/hbx/alias.js:46:20)  
11:48:40.610     at resolveWithSymlinks (/Applications/HBuilderX.app/Contents/HBuilderX/plugins/uniapp-cli-vite/node_modules/@dcloudio/uni-cli-shared/dist/resolve.js:20:30)  
11:48:40.614     at requireResolve (/Applications/HBuilderX.app/Contents/HBuilderX/plugins/uniapp-cli-vite/node_modules/@dcloudio/uni-cli-shared/dist/resolve.js:16:12)  
11:48:40.618     at Context.customResolver (/Applications/HBuilderX.app/Contents/HBuilderX/plugins/uniapp-cli-vite/node_modules/@dcloudio/vite-plugin-uni/dist/config/resolve.js:28:48)  
11:48:40.622     at Context.resolveId (file:///Applications/HBuilderX.app/Contents/HBuilderX/plugins/uniapp-cli-vite/node_modules/vite/dist/node/chunks/dep-5e7f419b.js:221:54)  
11:48:40.622     at Object.resolveId (file:///Applications/HBuilderX.app/Contents/HBuilderX/plugins/uniapp-cli-vite/node_modules/vite/dist/node/chunks/dep-5e7f419b.js:41433:46)  
11:48:40.626     at Object.<anonymous> (file:///Applications/HBuilderX.app/Contents/HBuilderX/plugins/uniapp-cli-vite/node_modules/vite/dist/node/chunks/dep-5e7f419b.js:61735:37)  
11:48:40.630     at Object.internalImporter (file:///Applications/HBuilderX.app/Contents/HBuilderX/plugins/uniapp-cli-vite/node_modules/vite/dist/node/chunks/dep-5e7f419b.js:36967:19)  
11:48:40.633     at JavaScriptObject.apply$2 (/Applications/HBuilderX.app/Contents/HBuilderX/plugins/compile-dart-sass/node_modules/sass/sass.dart.js:23739:23) {  
11:48:40.633   code: 'MODULE_NOT_FOUND'  
11:48:40.637 }  
2023-03-10 11:55 负责人:无 分享
已邀请:
仔仔_iZaiZaiA

仔仔_iZaiZaiA (作者) - 技术菜,又不想上班的废物打杂 - 仔仔

解决了,需要加 index.scss,文档上写的真坑

<style lang="scss">    
@import '@/uni_modules/uni-scss/index.scss';    

</style>
  • DCloud_UNI_WZF

    感谢反馈,已加分,文档已更新

    2023-03-13 11:41

j***@siline.cn

j***@siline.cn

我也是这个问题,但是我加了还是一样报错...

要回复问题请先登录注册