next-plugins icon indicating copy to clipboard operation
next-plugins copied to clipboard

next.config withSass build error: Invalid CSS after... webpack configuration

Open ercekal opened this issue 7 years ago • 2 comments

this is package.json

  "name": "with-apollo",
  "version": "2.0.0",
  "scripts": {
    "dev": "node server.js",
    "build": "next build",
    "start": "next start",
    "export": "next export",
    "storybook": "start-storybook -p 6006",
    "build-storybook": "build-storybook",
    "lint:fix": "eslint --fix components/ containers/",
    "test": "jest",
    "test:watch": "jest --watch",
    "test:coverage": "jest --coverage"
  },
  "jest": {
    "moduleNameMapper": {
      "\\.(css|less|scss|sss|styl)$": "<rootDir>/node_modules/jest-css-modules"
    }
  },
  "dependencies": {
    "@storybook/addon-links": "^5.0.10",
    "@zeit/next-css": "^1.0.1",
    "@zeit/next-sass": "^1.0.1",
    "@zeit/next-source-maps": "0.0.4-canary.1",
    "classnames": "^2.2.6",
    "eslint": "^5.16.0",
    "eslint-config-prettier": "^4.2.0",
    "express": "^4.16.4",
    "graphql": "^0.9.3",
    "i": "^0.3.6",
    "isomorphic-fetch": "^2.2.1",
    "next": "^8.0.4",
    "next-routes": "^1.4.2",
    "npm": "^6.9.0",
    "postcss-css-variables": "^0.12.0",
    "prop-types": "^15.5.8",
    "react": "^16.8.6",
    "react-apollo": "^1.1.3",
    "react-dom": "^16.8.6",
    "react-lazyload": "^2.5.0",
    "react-photoswipe": "^1.3.0",
    "react-redux": "^5.0.5",
    "react-scripts": "^3.0.0",
    "recompose": "^0.24.0",
    "redux-thunk": "^2.3.0",
    "sass-loader": "^7.1.0",
    "sass-resources-loader": "^2.0.0",
    "trackjs": "^3.3.0",
    "webpack": "^4.30.0"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "@storybook/addon-actions": "^5.0.10",
    "@storybook/react": "^5.0.10",
    "babel-core": "^6.26.3",
    "babel-jest": "^24.7.1",
    "babel-loader": "^8.0.5",
    "babel-preset-env": "^1.7.0",
    "babel-preset-react": "^6.24.1",
    "enzyme": "^3.9.0",
    "enzyme-adapter-react-16": "^1.12.1",
    "eslint-config-airbnb": "^17.1.0",
    "eslint-plugin-prettier": "^3.0.1",
    "jest": "^24.7.1",
    "jest-css-modules": "^2.0.0",
    "node-sass": "^4.12.0",
    "prettier": "^1.17.0",
    "redux-mock-store": "^1.5.3",
    "standard": "^12.0.1",
    "styled-jsx-plugin-sass": "^1.0.0"
  }
}```

this is babelrc
```{
  "presets": [
    [
      "next/babel",
      {
        "styled-jsx": {
          "plugins": [
            ["styled-jsx-plugin-sass", {
                "sassOptions": {
                  "includePaths": ["~/styles"],
                  "sourceMap": true
                }
              }
            ]
          ]
        }
      }
    ]
  ]
}```

this is the folder structure
```.storybook/
components/
-- footer/
    --styles.scss // imports variables.scss from (./styles/variables.scss)
    --footer.js // imports styles.scss via style-jsx
static/
-- fonts/
-- img/
styles/
--variables.scss
--mixins.scss

this is next.config.js

// next.config.js
module.exports = withSass({
  webpack: (config, { defaultLoaders }) => {
    config.resolve.alias['styles'] = path.join(__dirname, 'styles')
    config.module.rules.push({
      test: /\.scss$/,
      use: [
        defaultLoaders.babel,
        {
          loader: require('styled-jsx/webpack').loader,
          options: {
            type: 'scoped'
          }
        },
        {
          loader: 'sass-loader',
          options: {
            sourceMap: true
          }
        },
        {
          loader: 'sass-resources-loader',
          options: {
            resources: [
              './styles/*.scss'
            ]
          }
        }
      ]
    });
    return config;
  },
  async exportPathMap() {
    // need to find a solution for this... it's a hacky way
    const list = ['slate-bullet', 'bullet_new_navy', 'olive-bullet'];
    const pages = list.reduce(
      (pages, item) =>
        Object.assign({}, pages, {
          [`/products/${item}`]: {
            page: '/products',
            query: { productHandle: item }
          }
        }),
      {}
    );
    return Object.assign({}, pages, {
      '/products': { page: '/products' }
    });
  }
});```

when I try yarn build and/or yarn export

```> Using external babel configuration
> Location: "/Users/mike/Sites/spoke-reactify/.babelrc"
[styled-jsx] Loading plugin from path: /Users/mike/Sites/spoke-reactify/node_modules/styled-jsx-plugin-sass/index.js
Failed to compile.
./components/Layout/styles.scss
^
      Invalid CSS after "v": expected 1 selector or at-rule, was "var _defaultExport "
      in /Users/mike/Sites/spoke-reactify/components/Layout/styles.scss (line 1, column 1)
> Build error occurred```

ercekal avatar May 20 '19 13:05 ercekal

When you do a push it will add scss rule on top of existing one. If you console log inside you see two scss rules. You need to have only one scss rule. But even after combining the scss rule I am still getting errors on the files.

vikasdomakunti avatar Jul 29 '19 16:07 vikasdomakunti

Hi, thanks for creating an issue. We currently recommend using https://nextjs.org/docs/basic-features/built-in-css-support as the plugins have been deprecated in favor of the built-in support.

timneutkens avatar Dec 18 '20 07:12 timneutkens