简体   繁体   English

webpack 错误:未找到要导入的文件或无法读取的文件:bourbon ,如何解决?

[英]webpack error: File to import not found or unreadable: bourbon , how to fix?

I am trying to load the Bourbon package inside my SCSS files.我正在尝试在我的 SCSS 文件中加载 Bourbon 包。 I am using Angular 2 and this is my webpack 3.0 config:我正在使用 Angular 2,这是我的 webpack 3.0 配置:

var path = require("path");
var webpack = require("webpack");

module.exports = {
  devServer: {
    contentBase: path.join(__dirname, "build"),
    compress: true,
    port: 9000
  },
  node: {
    fs: 'empty'
  },
  cache: true,
  devtool: "eval", //or cheap-module-eval-source-map
  entry: {
    app: path.join(__dirname, "client/app", "app.js")
  },
  output: {
    path: path.join(__dirname, "buildf"),
    filename: "ha.js",
    chunkFilename: "[name].js"
  },
  plugins: [
    //Typically you'd have plenty of other plugins here as well
    new webpack.DllReferencePlugin({
      context: path.join(__dirname, "client"),
      manifest: require("./build/vendor-manifest.json")
    }),
  ],
  module: {
    loaders: [
      {
        test: /\.js?$/,
        loader: "babel-loader",
        include: [
          path.join(__dirname, "client") //important for performance!
        ],
        exclude: [
          path.join(__dirname, "node_modules")
        ],
        query: {
          cacheDirectory: true, //important for performance
          plugins: ["transform-regenerator"],
          presets: ["es2015", "stage-0"]
        }
      },

      { test: /\.(scss|sass)$/, loader: ['style-loader', 'css-loader', 'sass-loader'] },
      { test: /\.html$/, loader: 'raw-loader' },
      { test: /\.css$/, loader: 'css-loader' }
    ]
  }
};

When I run webpack I get this error:当我运行 webpack 时,我收到此错误:

ERROR in ./node_modules/css-loader!./node_modules/sass-loader!./client/app/app.scss Module build failed: @import "bourbon"; ./node_modules/css-loader!./node_modules/sass-loader!./client/app/app.scss 模块构建失败:@import "bourbon"; ^ File to import not found or unreadable: bourbon. ^ 要导入的文件未找到或无法读取:bourbon。 Parent style sheet: stdin in /Users/john/NG6-starter/client/app/app.scss (line 2, column 1) @ ./client/app/app.scss 4:14-116 @ ./client/app/app.component.js @ ./client/app/app.js @ multi (webpack)-dev-server/client?父样式表:/Users/john/NG6-starter/client/app/app.scss 中的 stdin(第 2 行,第 1 列)@ ./client/app/app.scss 4:14-116 @ ./client/app /app.component.js @ ./client/app/app.js @ multi (webpack)-dev-server/client? http://localhost:9000 ./client/app/app.js webpack: Failed to compile. http://localhost:9000 ./client/app/app.js webpack: 编译失败。

Why does the bourbon component cannot be found?为什么找不到波旁威士忌成分? Here is a link to the code这是代码的链接

June 2021 Update : In version 8.0.0 the development team of sass-loader has decided to move all SASS-related options to a sassOptions object inside options : 2021年6月更新在版本8.0.0的开发团队sass-loader已决定将所有SASS相关选项的sassOptions对象中options

module: {
    rules: [{
        test: /\.scss$/,
        use: [{
            loader: "style-loader"
        }, {
            loader: "css-loader"
        }, {
            loader: "sass-loader",
            options: {
                sassOptions: {
                    includePaths: ["node_modules/bourbon/core"],
                }
            }
        }]
    }]
}

Pre 8.0.0: 8.0.0 之前:

You need to pass options.includePaths to sass-loader :您需要将options.includePaths传递给sass-loader

module: {
    rules: [{
        test: /\.scss$/,
        use: [{
            loader: "style-loader"
        }, {
            loader: "css-loader"
        }, {
            loader: "sass-loader",
            options: {
                includePaths: ["node_modules/bourbon/core"]
            }
        }]
    }]
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Grunt Sass 错误:未找到或无法读取要导入的文件 - Grunt Sass Error: File to import not found or unreadable 错误:找不到要导入的文件或无法读取:~bootstrap/scss/bootstrap - Error: File to import not found or unreadable: ~bootstrap/scss/bootstrap 错误:找不到或无法读取要导入的文件:@fortawesome/fontawesome-free,Capybara,Rails 6.0.3 - Error: File to import not found or unreadable: @fortawesome/fontawesome-free , Capybara ,Rails 6.0.3 未找到或无法读取要导入的文件:node_modules/bootstrap/scss/functions - File to import not found or unreadable: node_modules/bootstrap/scss/functions 如何在 webpack 中捆绑 css 文件时修复“未知单词”错误 - How to fix 'Unknown word' error when bundling css file in webpack 在react中导入json文件,webpack配置错误 - import json file in react, webpack config error 未找到导入:使用 webpack 进行 web 开发时出现默认错误 - import not found: default error when using webpack for web development 尝试链接到 javascript 上的图像时如何修复找不到错误文件 - How to fix error file not found when trying to link to an image on javascript 如何使用 alchemy-web3 修复错误 - Webpack &lt; 5 - How to fix Error with alchemy-web3 - Webpack < 5 如何使用Webpack 2将&#39;require&#39;或&#39;import&#39;插入到js文件中? - How to insert 'require' or 'import' into js file with Webpack 2?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM