我正在嘗試使用 npm 將引導程式添加到我的目錄中。這是我的檔案結構:

我在 style.scss 檔案中使用 @import
@import "../node_modules/bootstrap/scss/bootstrap";
我的 package.json 看起來像這樣。它基本上是這個網站的初學者 - minimum-static-site-sass-setup
{
"name": "playground",
"version": "0.1.0",
"description": "SASS compile|autoprefix|minimize and live-reload dev server using Browsersync for static HTML",
"main": "public/index.html",
"author": "5t3ph",
"scripts": {
"build:sass": "sass --no-source-map src/sass:public/css",
"copy:assets": "copyfiles -u 1 ./src/assets/**/* public",
"copy:html": "copyfiles -u 1 ./src/*.html public",
"copy": "npm-run-all --parallel copy:*",
"watch:assets": "onchange \"/src/assets/**/*\" -- npm run copy:html",
"watch:html": "onchange \"src/*.html\" -- npm run copy:html",
"watch:sass": "sass --no-source-map --watch src/sass/:public/css",
"watch": "npm-run-all --parallel watch:*",
"serve": "browser-sync start --server public --files public",
"start": "npm-run-all copy --parallel watch serve",
"build": "npm-run-all copy:html build:*",
"postbuild": "postcss public/css/*.css -u autoprefixer cssnano -r --no-map"
},
"dependencies": {
"autoprefixer": "^10.4.2",
"bootstrap": "^5.1.3",
"browser-sync": "^2.27.7",
"copyfiles": "^2.4.1",
"cssnano": "^5.0.17",
"npm-run-all": "^4.1.5",
"onchange": "^7.1.0",
"postcss-cli": "^9.1.0",
"sass": "^1.49.8"
}
}
每次我嘗試編譯它時,我都會收到此錯誤:
"Error: Can't find stylesheet to import.
?
6 │ @import "../node_modules/bootstrap/scss/bootstrap";
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
?
src\sass\style.scss 6:9 root stylesheet"
我嘗試了許多來自 stackoverflow 的潛在解決方案,但似乎沒有一個對我有用。
任何想法,我做錯了什么?
uj5u.com熱心網友回復:
您可以嘗試:
@import "~node_modules/bootstrap/scss/bootstrap";
或者
@import "~bootstrap/scss/bootstrap";
uj5u.com熱心網友回復:
你最后不需要.css或類似的東西嗎?不應該有擴展嗎?
uj5u.com熱心網友回復:
@import "../../node_modules/bootstrap/scss/bootstrap";
錯誤的路徑,這就是問題:)
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/483148.html
