-
-
Notifications
You must be signed in to change notification settings - Fork 431
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Consider removing peerDependency node-sass and enforcing it at runtime instead #532
Comments
Yes! |
Why not put the equivalent "try-catch" wrapping in CRA? That is, do not have CRA depend on |
We don’t want to expose Webpack-specific concepts (such as “loaders”) to our user until they eject, or to give an impression that it’s supported to install loaders. So any solution that requires the user to install a webpack loader into their project doesn’t work for us. This would also prevent us from easily updating webpack under the hood (since that often involves updating loaders too). And we actually do that, e.g. we updated from webpack 2 to webpack 3 in a patch version (from our users’ point of view). |
That seems like a significant downgrade in experience for other users of sass-loader. If I'm installing sass-loader because I want to use it, why should I wait until runtime to see that I have an invalid dependency setup? The complexity here seems like it would be better handled by CRA. For example, CRA's tooling could detect if there are Sass files present, then prompt the user to install some additional package that wraps the behavior up – perhaps a |
I see the concern, and I understand why you want to avoid displaying a peer dep warning by default, especially in an explicitly newbie-friendly tool like CRA. Also, I realize that there are longstanding problems with the node sass binary that are unfortunate to impose even on users who don't plan on using sass. However, I think it's worth considering that How about something like a Edit: @taion beat me to the same general idea. :) |
Have you ever installed webpack, typed the config, and got it working right on the first try? I empathize with the concern here but I’m not sure how much practical difference it makes. You need to run it at least once to figure out what’s broken anyway. In my opinion, printing a friendly error message that tells you exactly what to do might be a better user experience than relying on npm to show a peer dependency warning in the sea of other output like
We don’t really plan to create a plugin system. I understand
Another problem with this is it doesn’t let our users pin their compiler version directly (which is somewhat important given that Sass is a binary and has all sorts of weird issues like segfaults).
I understand it is technically “correct”. But forcing people to download binaries that create weird issues for a use case only some people want is objectively worse experience. As far as I know, there is a precedent for this: I’ve heard that Parcel doesn’t install Sass by default, but prompts to install it on demand when it is used. I think we’re trying to do something similar, but indeed I don’t know if we can pull it off on top of webpack. This issue is my attempt to better understand this. I agree that maybe webpack might not be the best platform for building low-configuration solutions on top of, but it’s very popular in React ecosystem, and we wouldn’t want to migrate off of it in the near future unless absolutely necessary. |
Yeah! As a user, an ideal solution sounds something like:
So as a user of |
I came here to share exact same thoughts as shared by @taion above.
|
@taion For some reason I was less lucky 😢 Which is kind of my point—I don’t want CRA users to ever see something like this unless they explicitly opt in. |
👋 Node sass maintainer here. Happy to help where we can. Regarding the binary download issues, there's are largely unavoidable. As such we're investigating the feasibility of converting the binary to Web Assembly so a single artefact can be packaged in the npm download. |
I've had so many coworkers that have had all sorts of bizarre errors with node-sass and I've had plenty of my own issues as well. If it does get included in CRA I would want at the least better error messages, preferably with a link to common fixes for said messages. |
In my example, I'm not installing I don't think CRA needs a full-fledged plugin system to handle these sorts of optionals. What's wrong with something in https://github.com/facebookincubator/create-react-app/blob/v1.0.17/packages/react-scripts/config/webpack.config.dev.js like: let sassRule;
try {
sassRule = require('react-scripts-optional-sass').rule;
} catch (e) {
sassRule = null;
} Then only adding I don't think anybody's going to mistake this for a plugin system. |
Yes, of course. I'm looking for a solution that doesn't require this by default, and doesn't require sass-loader to do custom stuff. Best of both worlds, if we can make it work. :) If not, I think it's totally reasonable to fall back on a solution like the one you've proposed; sorry if I came across as shooting it down unconditionally.
So "plugin" is not the right name. But comparing this to the solution you proposed, they are both opt-in; they both require the user to install an additional package if they want sass. And isn't more obvious to a newbie what's going on if they are asked to install
Just brainstorming: this could be solved by having |
There are lots of things that users can't do with CRA, though! "Zero-config except you pick your version of If it came down to it, aside from ejecting, there are always Yarn resolutions. (Or installing |
I agree with the points @taion put here. I have nothing to add, but I'd just say that this seems like responsibility of CRA. |
I see, thanks for the discussion. I feel strongly that we don't want to expose our own separate addon-like package to the user, but I understand you feel strongly about this matter too. As a compromise, we might try writing a script that forks this package and does the necessary changes so we don't have to actively maintain a fork. If we find a way to make it low-effort and automatically "turn" into the official |
Thanks for bringing it up and for the discussion. Just wanted to note that until now, no sass-loader maintainer/contributor has answered on this issue so I'll just add my two cents here 😁: I totally understand CRA's point of view and I agree that a peer dependency warning is not really user friendly here. But I also think that from the sass-loader's perspective, a peer dependency is the right thing to do. In general, I came to the conclusion that for a lot of starter projects that don't require a lot of custom configuration, a generic "auto-loader" would really be useful. It would apply a sane default configuration for the common file extensions and delegate loader requests to the respective loader. All peer dependencies, on the other hand, would be delegated to the top-level application. It could also check if the required peer dependency is present in the project's scope and throw a helpful error. However, the auto-loader might cause unwanted peer dependency warnings. I don't know if NPM complains about missing peer dependencies if the dependency is available under |
I think we should use this way. Why?
Also we can improve error message ( |
The above comment makes sense to me. If multiple Sass implementations emerge (which, as I understand, is slowly happening), it would probably make sense for To give you some perspective on why I opened this issue at all: I didn’t expect that the From this thread though it seems like it has been valuable to you so I won’t try to persuade you from dropping them anymore. 🙂 Or maybe this is more of a ideological debate about how this feature “should” be used in which case I fully agree—in theory my proposal doesn’t make as much sense. |
Label as |
The most analogous case I can think of there is with WebSocket-based libraries that can use either I don't think I've ever seen a library that intentionally does not work out-of-the-box even with its peer dependencies installed, assuming those peer dependencies all live on npm. |
@evilebottnawi I'm not sure I see why this would be a breaking change except for npm@2 (which I'm not sure if you support). In other npm versions and Yarn, |
@gaearon minimum supported node |
This is fair, thanks for explaining. |
Not sure if you had considered this but an alternative approach could be to propose an NPM feature that allows you to suppress specific child deps' peer dependency warnings? Of course assuming it was added, you would still only be able to support NPM versions after that was released, which isn't great 😬 but 'twas just a thought that might prompt further discussion? |
@leonaves I've tried several npm feature recommendations, all of them got closed with no official response. They seem quite overloaded and Facebook even created Yarn as an alternative to npm, I am guessing partly for how dysfunctional npm has become in the last years. |
Coming to this thread from reading the 7.0.0 changelog and reading through all of it, I don't understand why the peer dependency was removed. Isn't warning about incompatible/missing versions at install time the whole point of peerDependencies? I dislike the thought that now if I have an incompatible sass version, I won't find out until rerunning webpack, and automated dependency updates have absolutely no way to determine this statically to coordinate an update. |
@felixfbecker in favor support |
Hey 👋
Create React App users have been very vocal about wanting to have Sass supported out of the box.
My personal concerns about
node-sass
haven't changed: it’s unfortunate to impose downloading a binary on each our user, and especially unfair to subject them to build issues like sass/node-sass#2146 if they’re not even planning to rely on Sass.But since the demand for Sass isn’t going away, I’d like to make it opt-in for our users. The ideal user experience would be that they don’t need to download
node-sass
by default and don’t see any peer dependency warnings, but if they attempt to import a Sass file, they will see an error message telling them to install a compatible version ofnode-sass
.The biggest roadblock to this experience is that
sass-loader
will just crash withoutnode-sass
installed. We could prevent this by putting our own custom loader in front of it, but this still doesn’t solve the scarypeerDependency
warning coming from our package if it depends onsass-loader
but notnode-sass
. And, as I mentioned above, we don’t want to force our users to installnode-sass
unless they actually plan to use it.Here is how
sass-loader
works today:peerDependency
onnode-sass
node-sass
doesn't exist,sass-loader
crashesHere is my proposal for how it could work:
peerDependency
onnode-sass
node-sass
is wrapped in atry
/catch
node-sass
is missing orrequire('node-sass').info
doesn’t match the compatible range, the loader issues a compilation error telling the user to install a compatible version ofnode-sass
This allows tools like Create React App to depend on
sass-loader
by default without creating hurdles for users who don’t want it. What do you think? We’d be happy to send a PR ourselves if you can get behind this change in behavior.The text was updated successfully, but these errors were encountered: