Are yarn and num interchangeable in practice?

I have a project with a package.json file and installing a bash script that, among other things, runs npm install .

I am thinking of updating the script so that it yarn install if yarn is available (to take advantage of yarn caching, a lock file, etc.), otherwise it returns to npm install . As far as I can tell, all the packages seem to install and work fine anyway.

Are yarn and npm interchangeable to make this a viable approach? Or are there potential problems that this could lead to? Do we just want to choose one or yarn interchangeable with npm in practice?

(nb. I read this close question , but I ask it as a separate question, because it relates to the explicit support of the yarn and npm installation processes in the project)

+7
installation npm yarnpkg
source share
1 answer

Yarn and npm (version> = 3.0.0) should be relatively compatible, especially moving from npm to yarn, since compatibility is one of the stated goals of yarn . As stated in Migrating with npm :

Yarn can use the same package.json format as npm, and can install any package from the npm registry.

So, theoretically, any package.json that is valid for npm should also work equally well for yarn. Note that I'm saying npm v2 is probably less compatible - this is because npm is moved from the nested node_modules structure to a flat layout (which is what Yarn uses). However, yarn and npm v3 should create very similar layouts because, as stated in the release, I'm connected :

As a first approximation, we should try to be very compatible with the node_modules layout for people who need this compatibility, because this will be the most likely way to avoid long tail problems.

However, you cannot use the Yarn.lock generated by Yarn, because (as the name implies) it is only supported with Yarn, and npm shrinkwrap incompatible.

In addition, as @RyanZim notes, older versions of Yarn do not support pre-and post-install hooks , but versions than v0.16.1 . If you rely on these hooks, you will need to tell users that versions greater than v0.16.1 .

In general, as long as you do not encounter errors and use only the functions that are shared by package managers, you should not have any problems.

+4
source share

All Articles