Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where and how to put the package.json in a tgz dependency

I'm trying to build a node library that will be stored into a .tgz

The issue is when I install this lib in another npm project, I have an error:

Non-registry package missing package.json: easy-rules-core@file:/Users/sbuisson/.m2/repository/org/jeasy/easy-rules-core-js/3.2.4/easy-rules-core-js-3.2.4.tgz.

The file structure of my tgz:

easy-rules-core-js-3.2.4.tgz
  -> package
     ->package.json
     ->index.js
     ->node_modules

I've also tried without success:

easy-rules-core-js-3.2.4.tgz
     ->package.json
     ->index.js
     ->node_modules

Where should I put the package.json?

Bonus question: Do I need to put the node_modules folder into the tgz?

like image 406
sab Avatar asked Dec 23 '22 22:12

sab


1 Answers

Try the npm pack command in your project folder. It should create a .tgz file structured correctly. It should be something like this (without the node_modules folder):

easy-rules-core-js-3.2.4.tgz
  -> package
     ->package.json
     ->index.js

Then copy the .tgz file in your parent module's root folder and run: npm install ./easy-rules-core-js-3.2.4.tgz.

This will handle the installation while adding the following line to your package.json: "easy-rules-core-js": "file:easy-rules-core-js-3.2.4.tgz". Alternatively you can add the dependency manually to the package.json.

More information:

  • https://docs.npmjs.com/cli/pack
  • https://docs.npmjs.com/cli/install
like image 171
horia Avatar answered Dec 27 '22 22:12

horia