Sass import not crawling node_modules to find appropriate package

孤者浪人 提交于 2019-12-24 01:09:39

问题


I am using bootstrap-sass. The node module is installed. I should expect I can, in any .scss file, use the below line to import into an appropriate sheet

@import 'bootstrap';

My understanding is what should happen is the compiler crawls up until it finds package.json, hops into node_modules, and finds the appropriate package. Instead I am getting the below error.

Error: File to import not found or unreadable: bootstrap

If I replace my import with a fully qualified path as below, then everything works gravily.

@import '../../node_modules/bootstrap-sass/assets/stylesheets/bootstrap';

I am using gulp-sass to compile. Guessing I just have some minor config bits off but I can't figure out what it is.


回答1:


Pass the path as an includes path....

Eg. It will look something like this if you're using gulp

.pipe(sass({
  includePaths: ['node_modules/bootstrap-sass/assets/stylesheets']
}))

Then you should be fine to use:

@import 'bootstrap';



回答2:


It will not import stuff like Javascript / Node.js. It will look for the bootstrap file in the same folder as the file which imports it. So yes, you need to use the long path or place the bootstrap file in the same folder.



来源:https://stackoverflow.com/questions/41511455/sass-import-not-crawling-node-modules-to-find-appropriate-package

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!