简体   繁体   中英

how do you use sass in create-react-app with typescript?

I created a fresh project using create-react-app and typescript and added a sass file in my project (in create-react-app docs it says that it supports sass file out of the box) but I'm getting this error for my sass file:

Failed to compile.

./src/homepage.style.sass (./node_modules/css-loader/dist/cjs.js??ref--6-oneOf-5-1!./node_modules/postcss-loader/src??postcss!./node_modules/resolve-url-loader??ref--6-oneOf-5-3!./node_modules/sass-loader/dist/cjs.js??ref--6-oneOf-5-4!./src/homepage.style.sass)
SassError: Invalid CSS after ".homepage {": expected "}", was "{"
        on line 1 of /home/taghi/wt-projects/react-ecommerce/src/homepage.style.sass
>> .homepage { {

   -----------^

and here is my Sass file content:

.homepage {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px 80px;
}

.directory-menu {
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
}

.menu-item {
  min-width: 30%;
  height: 240px;
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid black;
  margin: 0 7.5px 15px;

  &:first-child {
    margin-right: 7.5px;
  }

  &:last-child {
    margin-left: 7.5px;
  }

  .content {
    height: 90px;
    padding: 0 25px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border: 1px solid black;

    .title {
      font-weight: bold;
      margin-bottom: 6px;
      font-size: 22px;
      color: #4a4a4a;
    }

    .subtitle {
      font-weight: lighter;
      font-size: 16px;
    }
  }
}

Any help would be appreciated

Sass does not need curly brackets and semicolons. So it should look like this,

.homepage display: flex flex-direction: column align-items: center padding: 20px 80px

You can just remove the curly brackets and semicolons in the current CSS code or json Formatter to convert CSS to SASS.

It doesn't need "{}",only use indentation

.homepage 
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px 80px;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM