Skip to content

[9.3] CSS Modules cannot be imported from within node_modules #10975

@Danetag

Description

@Danetag

Bug report

Trying to migrate to next 9.3 and using the built-in sass feature.
When trying to use CSS modules with next 9.3, all my modules trigger the warning

./src/components/Footer/Footer.module.scss
CSS Modules cannot be imported from within node_modules

./src/components/Footer/Footer.module.scss
Module build failed: Error: Final loader (./node_modules/next/dist/build/webpack/loaders/error-loader.js) didn't return a Buffer or String

Describe the bug

I'm trying to properly migrate to Next 9.3 and use the built-in sass feature. When I have a file named *.module.scss (not even imported), I have warnings in the terminal saying that CSS Modules cannot be imported from within node_modules..

To Reproduce

  • Remove @zeit/next-sass from next.config.js and package.json
  • Remove .next folder
  • Add saas npm install sass
  • Create a file Something.module.scss. No need to import it.
  • Note the warnings in the terminal

Expected behavior

No warning should popup in the terminal.

System information

  • OS: macOS Mojave 10.14.6
  • Version of Next.js: 9.3.0
  • Version of Node: 13.9.0
  • Version of npm: 6.13.7

Additional context

I have updated next.config.js to be able to use the importing convention ~/ instead of ../

next.config.js

const path = require('path');

module.exports = {
  webpack: config => {
    // Alias
    config.resolve.alias['~'] = path.resolve(__dirname + '/src');
    return config;
  }
};

package.json

{
  "name": "...",
  "version": "0.1.0",
  "description": "...",
  "main": "index.js",
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start"
  },
  "keywords": [],
  "author": "...",
  "license": "MIT",
  "dependencies": {
    "@contentful/rich-text-react-renderer": "^13.4.0",
    "@optimizely/react-sdk": "^1.1.0",
    "bootstrap": "^4.4.1",
    "contentful": "^7.14.0",
    "isomorphic-unfetch": "^3.0.0",
    "next": "^9.3.0",
    "next-compose-plugins": "^2.2.0",
    "react": "^16.12.0",
    "react-bootstrap": "^1.0.0-beta.17",
    "react-dom": "^16.12.0",
    "react-optimize": "^2.2.1",
    "sass": "^1.26.2"
  }
}

Also, I'm using ZEIT Now, therefore in dev using:

now dev

Thank you for your help!

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions