calarin
calarin

Reputation: 236

How to add local .tgz file with Yarn 2?

I am trying to install a module onto an offline computer using Yarn 2.

I have the .tgz file of the NPM module. It looks like it can be done with Yarn 1.x but does not appear to work with Yarn 2.

I put the file lowdb-1.0.0.tgz into the root of the project folder for testing and tried these which did not work (project is configured for Yarn 2):

yarn add lowdb-1.0.0.tgz

YN0027: lowdb-1.0.0.tgz@unknown can't be resolved to a satisfying range
YN0001: RequestError: getaddrinfo ENOTFOUND registry.yarnpkg.com
...

yarn add ./lowdb-1.0.0.tgz

YN0000: Resolution step
YN0013: lowdb@file:./lowdb-1.0.0.tgz::locator=reaction%40workspace%3A. can't be found in the cache and will be fetched
YN0001: RequestError: getaddrinfo ENOTFOUND registry.yarnpkg.com
...

yarn add file:./lowdb-1.0.0.tgz

Internal Error: Invalid descriptor (file:./lowdb-1.0.0.tgz)
...

Is this possible to do with Yarn 2? Or is there another way to install modules directly onto an offline computer using downloaded assets/bundles/tgz using Yarn 2?

Upvotes: 5

Views: 2088

Answers (2)

exmaxx
exmaxx

Reputation: 3664

From the recent documentation for yarn add (v4 at the moment):

Add a local package (gzipped tarball format) to the current workspace :

yarn add local-package-name@file:../path/to/local-package-name-v0.1.2.tgz

This should work in your case (prepend the package name):

yarn add lowdb@file:./lowdb-1.0.0.tgz

It seems that the file option wasn't available in v3, but it has been introduced in v4.

Upvotes: 1

Look at https://classic.yarnpkg.com/lang/en/docs/cli/add/

yarn add $( pwd )/lowdb-1.0.0.tgz

Upvotes: 0

Related Questions