2

I have a project that requires some shared code, we basically have 2 types of client APIs and some similar functionality, call them client1 and client2. We have a project that has 4 directories, one for each client and library directories for api-common and api-logic. Each one has its own package.json with their respective dependencies and both client1 an client2 include the following:

"api-common": "file:../libs/api-common",
"api-logic": "file:../libs/api-logic",

Currently everyone of these modules includes a build script that transpiles into EC2015 using babel:

"build": "babel src -d dist",

For some reason npm install appears flaky. At times we find a run of npm install under the api-logic project (which depends on api-common) will fail:

npm ERR! path /home/user/workspace/server/libs/api-logic/node_modules/.staging/minimist-bb10354d
npm ERR! code ENOENT
npm ERR! errno -2
npm ERR! syscall rename
npm ERR! enoent ENOENT: no such file or directory, rename '/home/user/workspace/server/libs/api-logic/node_modules/.staging/minimist-bb10354d' -> '/home/user/workspace/server/libs/api-common/node_modules/rc/node_modules/minimist'
npm ERR! enoent This is related to npm not being able to find a file.

This doesn't really make much sense to me. I've already run npm install inside of api-common. It installed fine. I can see api-common/node_modules/rc/node_modules/minimist exists. Is there a better way of doing this? For some reason I get the feeling I should not be running babel until the very end when building client1 and client2.

Any help on best practices of code sharing within npm modules would be greatly appreciated. I'm very new to npm, so please assume nothing is obvious :)

TheHebrewHammer
  • 3,018
  • 3
  • 28
  • 45

0 Answers0