2

I have created an NPM module which is already built and published. so when somebody installs it, my module doesn't really need any extra dependency to work properly as it is already built.

However, the current behavior is that when I install my module in some other repository it updates some other modules in package-lock.json

Is there a way to avoid this behavior as my module is already pre-built and doesn't need any dependency to work properly?

Sivasankar
  • 753
  • 8
  • 22

2 Answers2

2

One way you can do this is create your project to be a nested project.

main-project
|- package.json
|- sub-project
   |-package.json

Once you build your files in the main-project place them in sub-project whose package.json has no dependencies listed. You can then publish your inner sub-project to npm as a dependency free module.

That being said, I think the common practice is to include your dependencies as usual - as long as you export your built file correctly and the users import them correctly, it should not matter that your dependencies are installed or not - when they build, ideally they include only what they need (and not your project's dependencies) if all goes well.

Chirag Ravindra
  • 4,760
  • 1
  • 24
  • 35
0

NPM has something called optionalDependencies.

npm install package-name --save-optional

This command will save your package as an optional dependency.

Then you can use

npm install --no-optional

to prevent installing the optional dependencies.

Nikhil Thakur
  • 317
  • 1
  • 7
  • I had thought about this solution but was thinking about more of a parameter to enable in npm itself. But anyway, thanks. – Sivasankar Feb 07 '19 at 04:39
  • Also, it would be good to give edit title or similar if you are changing the original answer with something completely new. – Sivasankar Feb 07 '19 at 05:34