Tuesday 30 October 2018

Problems with npm pack and npm install on CI server

I have a mono-repo with one main project, and a few supporting libraries that are separate packages. For the build process, we build the dependent projects then create tarballs with npm pack. Then, in package.json, we reference these tarballs like so:"library-one": "../library-one/library-one-0.2.1.tgz" This works great locally, the main application builds and runs like we'd expect. In this case, "locally" means on a MacBook Pro laptop.We also have a Drone CI server, and here is where I'm running into problems. The dependent projects build and pack fine, but when npm install is run in the main application, it blows up:Unhandled rejection Error: Integrity check failed: Wanted: sha512-rawpC6gbisQra9xbfsqxto/qfplJV2PzH0l5rFqT4E2PH60y7D1gmTXMzUVRaU6AyXzDtBY5gNYxgbA7pecx9g== Found: sha512-LvdlBy/rJnXZPcRc3f/ED2Spfq8vzw4LtZVNYHyWYt51jJGJMge2Yam6xaf/cqEkHqeOIR/k6RFSSdta6TM0cQ== Checking package-lock.json, I can see that the failed integrity checks are for the two dependent projects. I can't for the life of me figure out why the tarball would have a different sha512 on a Linux Drone server vs. a macOS laptop.Anyone ever run into something like this before?In case you're wondering why I am using npm pack: We are currently using yarn, and in package.json we refer to the dependent projects just by their directories, e.g.:"library-one": "../library-one/dist" When running npm install, yarn copies the ../library-one/dist folder into node_modules and everything works great.Trying to switch to use npm instead caused an issue. With npm, the relative path causes a symbolic link to be created instead of copying the directory. Which would normally be fine. Except, the main application is an Angular 6 app. For some reason I still can't figure out, when the dependent projects are symlinked, the Angular build fails horribly. That's a whole other issue.So the only solution I could find was to use npm pack to package the dependent projects up into tarballs, so that npm install would extract them into node_modules, effectively creating a copy of the directory.Edit: I should mention that I made sure I am using the exact same version of node and npm on my laptop that I am on the Drone CI server.

Submitted October 30, 2018 at 07:34PM by thinksInCode

No comments:

Post a Comment