question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Failing to load Sass from loadPreprocessor

See original GitHub issue

Describe the bug

I have a Sass file I’m including directly from my HTML. I’m getting a an error, Preprocessor dependency "sass" not found. Did you install it? when it tries to compile my Sass. Digging through Vite’s code, I see that resolved from loadPreprocessor is correctly finding the path to my Sass instance (/node_modules/sass/sass.default.dart.js). However, the preprocessor not found error gets thrown when trying to require it. This is where things get weird:

  • The file that it points to for Sass exists
  • If I require it using the same absolute path Vite finds in a top-level file, it requires fine.
  • If I do the same, but the top-level file is in Vite’s dist folder, it still requires fine.
  • requireing Sass at that exact line in Vite; (return (loadedPreprocessors[lang] = require(resolved));) makes Sass throw the following error:
TypeError: Cannot read property 'indexOf' of undefined
    at /.../repo/node_modules/sass/sass.dart.js:95027:12
    at Object.applyHooksTransformer (/.../repo/node_modules/sass/sass.dart.js:6871:14)
    at Object.initHooks (/.../repo/node_modules/sass/sass.dart.js:6851:251)
    at Object.initNativeDispatchContinue (/.../repo/node_modules/sass/sass.dart.js:6817:9)
    at Object.initNativeDispatch (/.../repo/node_modules/sass/sass.dart.js:6811:9)
    at Object.getNativeInterceptor (/.../repo/node_modules/sass/sass.dart.js:8705:13)
    at Object.getInterceptor$x (/.../repo/node_modules/sass/sass.dart.js:8961:16)
    at Object.set$info$x (/.../repo/node_modules/sass/sass.dart.js:8992:16)
    at Object.main (/.../repo/node_modules/sass/sass.dart.js:2420:9)
    at main1 (/.../repo/node_modules/sass/sass.dart.js:17897:9)

It only throws this error when it gets required from loadPreprocessor in Vite. Requiring it on its own elsewhere, everything seems to work!

Reproduction

Minimal failure case here. My best guess as to the problem is that Squoosh uses Node workers and simply requiring it throws Sass into thinking it’s in a browser.

System Info

System:
    OS: macOS 12.0.1
    CPU: (12) x64 Intel(R) Core(TM) i9-8950HK CPU @ 2.90GHz
    Memory: 390.18 MB / 32.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 14.18.1 - ~/.volta/tools/image/node/14.18.1/bin/node
    npm: 6.14.15 - ~/.volta/tools/image/node/14.18.1/bin/npm
  npmPackages:
    vite: ^2.7.0-beta.8 => 2.7.0-beta.8

Used Package Manager

npm

Logs

vite:load 5.52ms [fs] /sass/style.scss?direct +81ms
3:55:13 PM [vite] Internal server error: Preprocessor dependency "sass" not found. Did you install it?
  Plugin: vite:css
  File: /.../repo/src/sass/style.scss?direct
      at loadPreprocessor (/.../repo/node_modules/vite/dist/node/chunks/dep-d87be5e9.js:20620:15)
      at scss (/.../repo/node_modules/vite/dist/node/chunks/dep-d87be5e9.js:20625:20)
      at compileCSS (/.../repo/node_modules/vite/dist/node/chunks/dep-d87be5e9.js:20362:40)
      at async TransformContext.transform (/.../repo/node_modules/vite/dist/node/chunks/dep-d87be5e9.js:20011:50)
      at async Object.transform (/.../repo/node_modules/vite/dist/node/chunks/dep-d87be5e9.js:42740:30)
      at async doTransform (/.../repo/node_modules/vite/dist/node/chunks/dep-d87be5e9.js:57398:29)
  vite:time 67.47ms /sass/style.scss +61ms

Validations

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:8
  • Comments:13 (9 by maintainers)

github_iconTop GitHub Comments

4reactions
vanillajonathancommented, Mar 26, 2022

You need to install the Sass preprocessor.

npm install sass --save-dev
1reaction
vaasav-kumarcommented, May 17, 2022

You need to install the Sass preprocessor.

npm install sass --save-dev

installing only sass preprocessor is not enough… still am getting the dependency error

Read more comments on GitHub >

github_iconTop Results From Across the Web

Scss not loaded with Vite - Stack Overflow
The build with Vite and Vue works like a charm (so ist the path correct). However, it does not with storybook. Here my...
Read more >
sass-loader - webpack - JS.ORG
Loads a Sass/SCSS file and compiles it to CSS. ... Warning. Node Sass does not work with Yarn PnP feature and doesn't support...
Read more >
How do some Kirby themes preprocess SASS/LESS?
First, remember that just because a file has an extension '.scss', it doesn't mean that it is actually SCSS. The browser will (usually)...
Read more >
Automatically import SASS/SCSS into every Vue.js component
Sass Loader has been initialised using an options object that does not match the API schema. In which case, you may have an...
Read more >
Working with CSS - Vue CLI
If you did not do so, the internal webpack config is still pre-configured to ... Sass npm install -D sass-loader sass # Less...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found