Failing to load Sass from loadPreprocessor
See original GitHub issueDescribe 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, itrequire
s fine. - If I do the same, but the top-level file is in Vite’s
dist
folder, it stillrequire
s fine. require
ing 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
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn’t already an issue that reports the same bug to avoid creating a duplicate.
- Make sure this is a Vite issue and not a framework-specific issue. For example, if it’s a Vue SFC related bug, it should likely be reported to https://github.com/vuejs/vue-next instead.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:8
- Comments:13 (9 by maintainers)
Top GitHub Comments
You need to install the Sass preprocessor.
installing only sass preprocessor is not enough… still am getting the dependency error