Override NPM package with local version

This might not be a Meteor specific question, but rather NPM specific. I am using an NPM package that has some issues, and I want to contribute to it by debugging and fixing those issues. I have forked and cloned the repo, but now I don’t know how to make my Meteor app use that local version. I’ve tried using npm link but it didn’t really work. You guys must have experience doing this, I feel like I’m just missing something… How do you do this?

Just pass the directory path which contains your module to npm install command.

npm install --save ../path/to/mymodule

And it’d show up in package.json like so:

  "dependencies": {
    "bar": "file:../foo/bar"
  }

The only Meteor related thing you have to care for is to disallow Meteor from treating such directory as a Meteor related directory because of eager loading. I remember solving it by using .meteorignore but you can also have the modules/packages directory be inside imports directory.

1 Like

Thanks! Now I get this “more than one copy of React” error though:

image

Any idea how to solve that as well?

Make sure you’ve uninstalled the previously used NPM module. I’d recommend removing any duplicate entries in package.json and running rm -rf ./node_modules followed by meteor npm install to update package-lock.json.

I’ve previously used npm-link. Why didn’t it work for you?

When I use npm link I get this error:

% meteor npm link ../../../Code/React/motion -f
npm WARN using --force I sure hope you know what you are doing.
npm WARN read-shrinkwrap This version of npm is compatible with lockfileVersion@1, but package-lock.json was generated for lockfileVersion@2. I'll try to do my best with it!
npm ERR! code EEXIST
npm ERR! path /Users/Rijk/Code/React/motion/node_modules/.bin/yarn-deduplicate
npm ERR! Refusing to delete /Users/Rijk/Code/React/motion/node_modules/.bin/yarn-deduplicate: containing path /Users/Rijk/Code/React/motion/node_modules/yarn-deduplicate isn't under npm's control
npm ERR! File exists: /Users/Rijk/Code/React/motion/node_modules/.bin/yarn-deduplicate

Got it working by using my local NPM version instead of meteor npm. Apparently NPM v7 has a fix for the yarn-deduplicate error I got, because it worked with no problems. The NPM bundled with my Meteor project was v6.14.8. Thanks for the help @harry97 and @wildhart.

1 Like