How to downgrade Gatsby version from 3.14.2 to ^2.0.0 - npm

I have a Gatsby starter (taylorbryant/gatsby-starter-tailwind) that uses gatsby-plugin-postcss which is not compatible with the version of gatsby installed in my machine like a few other plugins used in the starter. You can see the warning I get when trying to build for production.
warn Plugin gatsby-plugin-postcss is not compatible with your gatsby version 3.14.2 - It requires gatsby#^2.0.0
How can I downgrade Gatsby to a specific version, maybe just locally?

This isn't too difficult.
Open your package.json file and change the actual version you want to use.
Then run npm update to make sure you update all the packages to the right version.
Please correct me if I'm wrong but I believe that is the way to change the Gatsby version.
Please do keep in mind that this is most probably cause a bunch of other discrepancies with other packages that actually require a higher version in order to work.
You can find more information about how different versions work here: https://www.gatsbyjs.com/docs/reference/release-notes/migrating-from-v2-to-v3/
Best of luck!

Related

Upgrading NPM from 5.8 to latest

I want to look at upgrading NPM on a project I'm working on from 5.8.0 to the latest version.
Is this something that is safe to do without breaking any packages i have installed? And if there's a chance it might, what is the best method for testing those packages to make sure everything is running correctly still?
Updating NPM is unlikely to break anything. However your packages may require a certain version of Node.js to function properly.
There also isn't really a "best method" to check if everything runs correctly. Ill refer you to this answer which has a few options you can try.

force node-sass to use lib-sass 3.6.0

I am using node-sass 4.13.1 which wraps libsass 3.5.4.
Due to security reasons we need to update libsass to 3.6.0 without downgrading the node-sass version.
How can this be achieved. Specifying the libsass version in the package.json is not feasible since libsass is not a dependency but rather a wrapped library.
Is it possible to force the use of libsass 3.6.0 after all dependencies for the repo have been installed?
Does anybody know a better solution?
I am leaning towards looking into how i can edit the scripts part of the package.json file to run a pre-install script which will force the version. Is that a good idea?
Thanks
There are forked versions of node-sass that do have 3.6.x in them, as well as a branch within the main project repo. The problem is that you will have to build it yourself in order to use them.
https://github.com/ItsLeeOwen/node-sass/tree/libsass-2b8a17a
or
https://github.com/sass/node-sass/tree/libsass-3.6.1
for example.
There is a branch available in node-sass repository which uses LibSass v3.6.3 with node-sass v4.13.1
I also faced the same issue and after doing a lot of research, the below solution worked for me:
Try installing the branch of node-sass from the github repository by using the below command (the package is already built, so you don't have to build it explicitly)
npm install https://github.com/sass/node-sass.git#v5

Any way to check that package.json engines satisfies version of global installed packages/binaries?

As I understand, the engines object is only for cases where someone installs my application. I would like to have something similar where I can prevent compiling errors on employee systems (because of wrong node versions etc.) before they happen.
I found that there are two packages:
https://github.com/jgillich/npm-check-engines/blob/master/index.js
https://github.com/kruppel/check-engines
But they are not working or not doing what I want.
It would be nice to have a script running before npm install that checks these engines versions and if they are available in path.
I created a package that does this.
https://github.com/muuvmuuv/npm-supervisor
It can be run via npm before installation and will check if a version in engines satisfies the global or local installed version.

How do I upgrade ember-cli-babel?

The online NPM documentation does not explain how to upgrade ember-cli-babel. I tried following the accepted answer posted here Invalid Version: Ember-Cli-Babel, but that did not work.
DEPRECATION: ember-cli-babel 5.x has been deprecated. Please upgrade
to at least ember-cli-babel 6.6. Version 5.2.8 located: library-ui ->
ember-clean-tmp -> ember-cli-babel
Update
I have uninstalled the Ember-clean-tmp add-on. When I run Ember-cli-update I get a message that says Tags match, nothing to apply. I then ran Ember S and get the following warnings:
WARNING: ember-basic-dropdown attempted to include external babel
helpers to make your build size smaller, but your root app's
ember-cli-babel version is not high enough. Please update
ember-cli-babel to v7.3.0-beta.1 or later.
WARNING: ember-power-select attempted to include external babel
helpers to make your build size smaller, but your root app's
ember-cli-babel version is not high enough. Please update
ember-cli-babel to v7.3.0-beta.1 or later.
WARNING: ember-data attempted to include external babel helpers to
make your build size smaller, but your root app's ember-cli-babel
version is not high enough. Please update ember-cli-babel to
v7.3.0-beta.1 or later.
WARNING: ember-basic-dropdown attempted to include external babel
helpers to make your build size smaller, but your root app's
ember-cli-babel version is not high enough. Please update
ember-cli-babel to v7.3.0-beta.1 or later.
WARNING: ember-text-measurer attempted to include external babel
helpers to make your build size smaller, but your root app's
ember-cli-babel version is not high enough. Please update
ember-cli-babel to v7.3.0-beta.1 or later.
WARNING: ember-power-select attempted to include external babel
helpers to make your build size smaller, but your root app's
ember-cli-babel version is not high enough. Please update
ember-cli-babel to v7.3.0-beta.1 or later.
Update 2
I was able to fix the issue by uninstalling ember-cli-babel and re-installing it, which got me to version 7.5.0. But, is this the correct way to upgrade packages?
The problem that you are experiencing is related to one of your addon's depending on an older version of ember-cli-babel.
From the deprecation notice, it's ember-clean-tmp, which doesn't look to be up to date. You have a number of options here. First, you could stop using the addon (which in this case doesn't really seem like a necessary addon. Needing to clear my tmp has never been a problem for me in my 2.18 app).
Secondly, if you'd like to keep using the addon, you could go through the process of upgrading the addon's ember-cli version to a version that includes a high enough ember-cli-babel version. Basically, each ember-cli version has a default blueprint for what dependencies a new app should include. When you ugprade, you diff your dependencies and various files against the default for that ember-cli version. ember-cli-update is an addon that makes this process nice. You can then point at your own fork or better yet, get your update merged upstream in ember-clean-tmp
Open you Command Prompt and type ember install ember-cli-babel and press enter. If you have already installed, don't worry. This will over write.
Reference: https://www.npmjs.com/package/ember-cli-babel
First,
npm install ember-svg-jar
Second,
ember install ember-svg-jar
All I had to do were these commands.

How to make npm use the lowest version that matches all requirements

We're using NodeJS for some projects and are faced with an issue that must have a simple solution (seeing as nobody else seems to have the problem).
In the packages.json there are a bunch of dependencies mentioned with a minimum version, each of which may have overlapping dependencies of their own. The default way a dependency is added is using the ^ operator which seems to mean 'compatible with' or 'same major version, but minor versions may differ'.
The way I understand npm to work is on npm install to take the highest minor version available that matches. Unfortunately 'compatible with' is not quite as enforced as you'd hope.
The situation this puts us in is that for instance on a developer machine version 1.1.0 is installed, but between development and publishing a new version 1.2.0, that has a bug, is introduced. On our build machine a fresh build is made which ends up using 1.2.0 and we've introduced a bug that wasn't there in development.
We tried changing the ^ operator to = for instance, but this gives us trouble when dependencies have subdependencies that aren't compatible with the requested version.
All in all I'm a bit confused, but this thing keeps biting us anytime something changes since the development machines don't do anything on npm install if the package is already there, but the build machine always gets fresh copies.
I know from NuGet that it always takes the lowest version that matches all combined requirements. Since this is always the same for a given set of dependencies, I much prefer this approach. Is there a way to make npm work like this too?
To answer my own question:
npm has introduced a new command npm ci which does something similar to npm install but enforces that the specific versions are used that were also used when a package was initially added by using the package-lock file.
See https://docs.npmjs.com/cli/ci for more information