Skip to content

[BUG] Error when extracting a directory after updating from 13.0.4 to 15.0.3 #241

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

Closed
1 task done
dutchigor opened this issue Oct 27, 2022 · 2 comments
Closed
1 task done
Labels
Bug thing that needs fixing Needs Triage needs an initial review

Comments

@dutchigor
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

Hi,

I use Pacote to install packages in electron during runtime. I just updated from 13.0.4 to 15.0.3 and one of my test cases now fails with the error: DirFetcher requires either a tree or an Arborist constructor to pack.
This test case takes a valid package (only package.json) from an existing folder and extracts it to the installation folder.

After looking in to your source code, I found that Arborist is now required for extracting a directory. Simply importing Arborist as a dependency and including it as an option in the extract call seems to solve my problem. However, I have no idea what this actually does. Is this the correct solution to my problem or will this cause other problems in production with other specifier types?

Expected Behavior

Calling extract with just a source dir as spec and destination dir as dest should successfully move a valid package from ./pluginsSrc to ./plugins.

Steps To Reproduce

  1. In a new npm project with pacoate as dependency, create a folder called pluginSrc and add a valid package.json in it.
  2. Create another folder in the test folder called pluginDest
  3. Execute the following js:
    const { extract } = require("pacote")
    extract('./pluginSrc', './ pluginDest')

Environment

  • npm: 8.15.0
  • Node: 16.17.0
  • OS: Windows 10
  • platform: ASUS Zenbook
@dutchigor dutchigor added Bug thing that needs fixing Needs Triage needs an initial review labels Oct 27, 2022
@wraithgar
Copy link
Member

That is the correct solution. This is due to a circular dependency on arborist that we have in pacote.

@ilg-ul
Copy link

ilg-ul commented Feb 8, 2023

I also encountered this issue:

ilg@wksi ~ % pacote extract ~/tmp/empty ~/tmp/empty-dest
Error: DirFetcher requires either a tree or an Arborist constructor to pack
    at DirFetcher.[pacote.Fetcher._tarballFromResolved] (/Users/ilg/.nvm/versions/node/v16.18.0/lib/node_modules/pacote/lib/dir.js:65:13)
    at retry.retries (/Users/ilg/.nvm/versions/node/v16.18.0/lib/node_modules/pacote/lib/fetcher.js:330:64)
    at /Users/ilg/.nvm/versions/node/v16.18.0/lib/node_modules/pacote/node_modules/promise-retry/index.js:29:24
ilg@wksi ~ % 

where ~/tmp/empty is an empty project created with npm init.

The solution was indeed to import arborist and pass it to extract via the options

import { Arborist } from '@npmcli/arborist'

...

        const fetchResult = await pacote.extract(
          fromFolderPath,
          destinationFolderPath,
          { cache: cacheFolderPath, Arborist })

However, the documentation does not mention anything about this option.

If passing an Arborist to extract() is part of the mandatory module API, could you document it properly?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug thing that needs fixing Needs Triage needs an initial review
Projects
None yet
Development

No branches or pull requests

3 participants