Sass loader cannot resolve modules from Yarn v2 PNP
See original GitHub issueBug report
Describe the bug
Next.js does not resolve SCSS that is imported by my dependencies:
styles/home.module.scss
uses@material/elevation
(this works fine).@material/elevation
uses@material/animation
(this fails).
To Reproduce
Steps to reproduce the behavior, please provide code snippets or a repository:
- First, clone this repository and CD inside:
$ git clone https://github.com/nicholaschiang/with-sass
$ cd with-sass/
- Then, make sure you have Yarn installed then run:
$ yarn
- Finally, start the development server by running:
$ yarn dev
Error
You’ll notice that when you run yarn dev
the Next.js server starts up properly
but the sass-loader
is unable to resolve my dependency’s imports.
It seems to import the @material/elevation
package just fine:
// styles/home.module.scss
@use '@material/elevation
But it doesn’t seem to be able to import @material/animation
for the
@material/elevation
package:
error - ./styles/home.module.scss (./.yarn/$$virtual/css-loader-virtual-393ee7c517/0/cache/css-loader-npm-3.5.3-0f886851e6-910936f0ac.zip/node_modules/css-loader/dist/cjs.js??ref--5-oneOf-3-1!./.yarn/$$virtual/next-virtual-4df8b3b97e/0/cache/next-npm-9.5.1-e14f31e6e9-effa9056b8.zip/node_modules/next/dist/compiled/postcss-loader??__nextjs_postcss!./.yarn/cache/resolve-url-loader-npm-3.1.1-cf1a268137-7b113ac9e6.zip/node_modules/resolve-url-loader??ref--5-oneOf-3-3!./.yarn/$$virtual/sass-loader-virtual-dbafe3ebab/0/cache/sass-loader-npm-8.0.2-f0d209ad64-e23d9b308f.zip/node_modules/sass-loader/dist/cjs.js??ref--5-oneOf-3-4!./styles/home.module.scss)
SassError: Can't find stylesheet to import.
╷
23 │ @use "@material/animation/variables";
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
╵
.yarn/cache/@material-elevation-npm-7.0.0-aaa8862010-5ea26d080e.zip/node_modules/@material/elevation/_variables.scss 23:1 @forward
.yarn/cache/@material-elevation-npm-7.0.0-aaa8862010-5ea26d080e.zip/node_modules/@material/elevation/_index.scss 1:1 @use
/home/nchiang/repos/with-sass/styles/home.module.scss 1:1 root stylesheet
I’ve had this error before when using Next.js with
MWC but was
able to fix it by specifying an includePaths
configuration in next.config.js
like so:
// next.config.js
const path = require('path');
module.exports = {
sassOptions: {
includePaths: [
path.resolve(__dirname, 'node_modules'),
],
},
};
Now, I’m not sure how to tell sass-loader
to use Yarn PNP’s module resolution.
Expected behavior
Next.js should be able to resolve the Yarn PNP modules.
System information
- OS: Ubuntu 18.04.2
- Version of Next.js: 9.5.1
- Version of Node.js: 14.7.0
Issue Analytics
- State:
- Created 3 years ago
- Comments:18 (18 by maintainers)
Top Results From Across the Web
Yarn 2 and dart sass with create react app - Stack Overflow
It looks like yarn 2 provides a way of overriding a packages dependencies. ... sass-loader itself has defined its dependencies correctly.
Read more >sass-loader | Yarn - Package Manager
Why can you remove it? The loader will first try to resolve @import as a relative path. If it cannot be resolved, then...
Read more >FAQ - Eufemia - DNB Design System
The Storybook setup is using the default @storybook/preset-scss addon with the recommended dependencies. But for some reason, we can't use the latest versions ......
Read more >Yarn Plug'n'Play: Getting rid of node_modules | Hacker News
It just works because it's literally what Node uses to resolve paths, and all build tools are based on Node, so when you...
Read more >cannot find module or its corresponding type declarations.ts ...
2. I execute yo code generate a project with webpack. It has a error in src/extensions.ts : Cannot find module 'vscode' or its...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Fixed in https://github.com/vercel/next.js/pull/16970
Fixed, ETA is tomorrow, I found other strange resolution bug (very rare case), anyway you need to update
sass-loader
to latest, it will not work withsass-loader@8