Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when targeting two projects where one is also a dependency of the other #10

Open
greyepoxy opened this issue Oct 15, 2020 · 1 comment
Labels
bug Something isn't working

Comments

@greyepoxy
Copy link
Contributor

Bug Description

When running npm-pack-here using the globalCacheOption for two targets, where one of the targets is a also a dependency of the other target, an error will occur like the following.

error: multiple targets are trying to pack to destination '<workingDirectory>\node_modules\<projectC>', targets: [<path-to-projectC>, <path-to-npm-pack-here-global-cache>\<projectC>]

Steps to Reproduce the Problem

Say you have three projects with the following dependency relationships

  • projectA depends on projectB and projectC
  • projectB depends on projectC (the same version as projectA)

Then running the following commands:

  1. In projectB run npm-pack-here --target <path-to-projectC> --useGlobalCache
  2. In projectB run the follow up yarn/npm commands to setup projectC as a local dependency, for example in this case using yarn
    a. yarn add file:<path-to-npm-pack-here-global-cache>/<name-of-projectC>
    b. yarn install --check-files
  3. Then in projectA run npm-pack-here --target <path-to-projectB> <path-to-projectC> --useGlobalCache

Expected Result

No errors and the local versions of projectB and projectC pulled into projectA's node_module directory

Actual Result

The following error

error: multiple targets are trying to pack to destination '<projectA>/node_modules/<projectC>', targets: [<path-to-projectC>, <path-to-npm-pack-here-global-cache>/<projectC>]

Additional Context

  • Node/npm version: Node v12.18.3
  • Yarn: 1.22.4
  • OS: windows 10
@greyepoxy greyepoxy added the bug Something isn't working label Oct 15, 2020
@greyepoxy
Copy link
Contributor Author

greyepoxy commented Oct 15, 2020

Main issue here is that the way npm-pack-here figures out additional local dependencies that should be packed is by looking at a project's package.json dependencies or devDependencies. If it detects a "file" reference it follows the path to the given destination and packs the content there. That means that the packed content is targeted (not the original source of that packed content). Usually, this is not a problem but in a case as described here, it becomes one as both the original source and the packed content location are targeted.

One option to fix this is to add a .npm_pack_here file to the destination location of any packed content. That file could then have a reference back to the original target/source of the given packed content. Then when a folder with one of these files is indicated as the "target/source" (most likely through a multi level local dependency flow as described above), npm-pack-here can get the original target location to pack from.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant