I’m on a old/new project based on node/express where boostrap source was painfully copy-pasted (and hacked).
I want to use bootstrap package to be more maintainable. But, after adding bootstrap-sass and node-sass, I face this error:
Here’s the error
in /vagrant/sass/theme.scss:28:1
Error: File to import not found or unreadable: bootstrap/variables
Parent style sheet: /vagrant/sass/theme.scss
at options.error (/vagrant/node_modules/node-sass/lib/index.js:277:32)
source: /vagrant/sass/vendor/bootstrap-datepicker/css/bootstrap-datepicker3.min.scss
dest: /vagrant/public/css/vendor/bootstrap-datepicker/css/bootstrap-datepicker3.min.css
read: /vagrant/public/css/vendor/bootstrap-datepicker/css/bootstrap-datepicker3.min.css
source: /vagrant/sass/theme.scss
dest: /vagrant/public/css/theme.css
read: /vagrant/public/css/theme.css
error: File to import not found or unreadable: bootstrap/variables
Parent style sheet: /vagrant/sass/theme.scss
in /vagrant/sass/theme.scss:28:1
Error: File to import not found or unreadable: bootstrap/variables
Parent style sheet: /vagrant/sass/theme.scss
at options.error (/vagrant/node_modules/node-sass/lib/index.js:277:32)
server.js
app.use(
sass({
src: __dirname + '/sass',
dest: __dirname + '/public/css',
prefix: '/css',
// outputStyle: 'compressed',
debug: true,
})
);
package.json:
"dependencies": {
"bcrypt-nodejs": "0.0.3",
"body-parser": "^1.13.1",
"bootstrap-sass": "^3.3.6",
"connect-flash": "^0.1.1",
"cookie-parser": "^1.3.5",
"express": "^4.12.4",
"express-session": "^1.11.3",
"mysql": "^2.7.0",
"node-sass": "^3.4.2",
"node-sass-middleware": "^0.9.7",
"passport": "^0.2.2",
"passport-facebook": "^2.0.0",
"passport-google-oauth": "^0.2.0",
"passport-local": "^1.0.0",
"passport-twitter": "^1.0.3",
"randomstring": "^1.1.3",
"sendgrid": "^1.9.2",
"sequelize": "^3.9.0",
"sequelize-fixtures": "^0.4.8",
"shelljs": "^0.5.3",
"swig": "^1.4.2"
},
"devDependencies": {
"eslint": "^1.10.3",
"gulp": "^3.9.0",
"gulp-zip": "^3.0.2",
"jake": "^8.0.12",
"minimist": "^1.2.0",
"node-sass": "^3.3.3",
"node-sass-middleware": "^0.9.6"
}
theme.scss
/*!
* Bootstrap v3.3.6 (http://getbootstrap.com)
* Copyright 2011-2015 Twitter, Inc.
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
*/
// Core variables and mixins
@import "bootstrap/variables";
@import "bootstrap/mixins";
// Reset and dependencies
@import "bootstrap/normalize";
@import "bootstrap/print";
@import "bootstrap/glyphicons";
// Core CSS
@import "bootstrap/scaffolding";
@import "bootstrap/type";
@import "bootstrap/code";
@import "bootstrap/grid";
@import "bootstrap/tables";
@import "bootstrap/forms";
@import "bootstrap/buttons";
// Components
@import "bootstrap/component-animations";
@import "bootstrap/dropdowns";
@import "bootstrap/button-groups";
@import "bootstrap/input-groups";
@import "bootstrap/navs";
@import "bootstrap/navbar";
@import "bootstrap/breadcrumbs";
@import "bootstrap/pagination";
@import "bootstrap/pager";
@import "bootstrap/labels";
@import "bootstrap/badges";
@import "bootstrap/jumbotron";
@import "bootstrap/thumbnails";
@import "bootstrap/alerts";
@import "bootstrap/progress-bars";
@import "bootstrap/media";
@import "bootstrap/list-group";
@import "bootstrap/panels";
@import "bootstrap/responsive-embed";
@import "bootstrap/wells";
@import "bootstrap/close";
// Components w/ JavaScript
@import "bootstrap/modals";
@import "bootstrap/tooltip";
@import "bootstrap/popovers";
@import "bootstrap/carousel";
// Utility classes
@import "bootstrap/utilities";
@import "bootstrap/responsive-utilities";
I’m new to node, coming from Rails where setupping bootstrap with sass was really easy. Let me know if you need additional files/info about the project.
Thank you for help!
2
Answers
I had a similar issue when importing
bootstrap-sass
to a React/Webpack project, but the solution is the same. In your main scss file (theme.scss), you need @import individual mixins via the relative paths inside the node_modules package minus thenode_modules
path segment.If you are pulling individual features then you need to change the
@import "bootstrap/feature"
path to reflect the path of every feature you want to use in the bootstrap-sass package. Also note the preceding~
in the path, which resolves an error for navigating the to SCSS files.Another gotcha, if you are pulling in the glyphicons you are going to need to set the
$icon-font-path
to point to the fonts folder in the package, or else the server will error out for finding those files.If you just want to use everything in the package, you can just set the icon-font-path and pull in all the styles like so in your theme.scss file.
I had a similar issue when importing bootstrap-sass in angular and gulp-sass. in my project problem resolve with