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

npm test fails when opening archive #56042

Closed
noahtallen opened this issue Sep 28, 2021 · 18 comments · Fixed by microsoft/DefinitelyTyped-tools#408
Closed

npm test fails when opening archive #56042

noahtallen opened this issue Sep 28, 2021 · 18 comments · Fixed by microsoft/DefinitelyTyped-tools#408

Comments

@noahtallen
Copy link
Contributor

noahtallen commented Sep 28, 2021

Update: This is caused by npm/cli#3405. npm pack outputs the filename in its info as @pakage/foo.tar.gz, but actually saves it as package/foo.tar.gz. As a result, when dts-critic does to open that tar.gz, it has the wrong filename, and the tests fail. This happens on newer npm versions, and can be worked around by using npm v6.

When running npm run test locally, I am getting the following error:

➜  DefinitelyTyped git:(update/wp-components-v17) npm run test wordpress__components 

> definitely-typed@0.0.3 test
> dtslint types "wordpress__components"

tar (child): @wordpress/components-17.0.0.tgz: Cannot open: No such file or directory
tar (child): Error is not recoverable: exiting now
tar: Child returned status 2
tar: Error is not recoverable: exiting now

I get the same error whether I use @wordpress/components or wordpress__components. From what I can tell, the file is being saved, but without the leading @ symbol. For example:

➜  DefinitelyTyped git:(update/wp-components-v17) npm run test @wordpress/components

> definitely-typed@0.0.3 test
> dtslint types "@wordpress/components"

tar (child): @wordpress/components-17.0.0.tgz: Cannot open: No such file or directory
tar (child): Error is not recoverable: exiting now
tar: Child returned status 2
tar: Error is not recoverable: exiting now
➜  DefinitelyTyped git:(update/wp-components-v17) ls word* 
wordpress-components-17.0.0.tgz

So it attempts to open @wordpress/components..., but the saved file is actually wordpress/components.... I poked around in dtslint, but I couldn't find anywhere it tries to run tar commands.

@peterblazejewicz
Copy link
Member

@wordpress/components is a proper name to use here.

I think it should work, you've got some strange problem as your local setup tried to resolve this as external dependenc. This one is from Debian (WSL2):

➜  DefinitelyTyped git:(master) cd types/wordpress__components
➜  wordpress__components git:(master) ls
angle-picker-control   date-time           higher-order              placeholder         spinner
...
custom-select-control  form-toggle         package.json              slot-fill
dashicon               form-token-field    panel                     snackbar
➜  wordpress__components git:(master) npm i --no-package-lock

added 24 packages, and audited 25 packages in 6s

found 0 vulnerabilities
➜  wordpress__components git:(master) cd ../..
➜  DefinitelyTyped git:(master) npm test @wordpress/components

> definitely-typed@0.0.3 test
> dtslint types "@wordpress/components"

➜  DefinitelyTyped git:(master)

so the @ syntax should work, there is no special support for this, except of proper line in DTLint itself to handle namespaced packages (by a path translation):
https://github.com/microsoft/dtslint/blob/07fcc2634f9bd1a5b15f29092261ef5726b42170/src/index.ts#L63

@noahtallen
Copy link
Contributor Author

Cool, I'll keep looking. Is it possible Linux is unsupported? I'll also try on macOS.

Running the same commands for me:

➜  DefinitelyTyped git:(update/wp-components-v17) ls
azure-pipelines.yml     README.es.md  README.ru.md
dangerfile.ts           README.it.md  README.zh.md
LICENSE                 README.ja.md  types
node_modules            README.ko.md  wordpress-components-17.0.0.tgz
notNeededPackages.json  README.md
package.json            README.pt.md
➜  DefinitelyTyped git:(update/wp-components-v17) cd types/wordpress__components
➜  wordpress__components git:(update/wp-components-v17) ls                            
angle-picker-control  custom-select-control  font-size-picker          menu-items-choice    radio-control       textarea-control
animate               dashicon               form-file-upload          modal                range-control       text-control
autocomplete          date-time              form-toggle               navigable-container  resizable-box       toggle-control
base-control          disabled               form-token-field          node_modules         responsive-wrapper  toolbar
button                draggable              higher-order              notice               sandbox             toolbar-button
button-group          dropdown               icon                      package.json         scroll-lock         tooltip
card                  dropdown-menu          icon-button               package-lock.json    select-control      tree-select
checkbox-control      drop-zone              index.d.ts                panel                shortcut            tsconfig.json
clipboard-button      external-link          isolated-event-container  placeholder          slot-fill           tslint.json
color-indicator       flex                   keyboard-shortcuts        popover              snackbar            wordpress__components-tests.tsx
color-palette         focal-point-picker     menu-group                primitives           spinner
color-picker          focusable-iframe       menu-item                 query-controls       tab-panel
➜  wordpress__components git:(update/wp-components-v17) npm i --no-package-lock

changed 1 package, and audited 25 packages in 2s

found 0 vulnerabilities
➜  wordpress__components git:(update/wp-components-v17) cd ..
➜  types git:(update/wp-components-v17) npm test @wordpress/components

> definitely-typed@0.0.3 test
> dtslint types "@wordpress/components"

tar (child): @wordpress/components-17.0.0.tgz: Cannot open: No such file or directory
tar (child): Error is not recoverable: exiting now
tar: Child returned status 2
tar: Error is not recoverable: exiting now

@peterblazejewicz
Copy link
Member

No, I don't think so Linux is unsupported. All CI actions are run on Ubuntu (same installs). I cannot use native *nix at the moment, by my WSL2 Ubuntu/Debian distros do not show this problem

➜ types git:(update/wp-components-v17) npm test @wordpress/components

this should be on parent/root of the repo:

➜ git:(update/wp-components-v17) npm test @wordpress/components

@noahtallen
Copy link
Contributor Author

No, I don't think so Linux is unsupported

👍

this should be on parent/root of the repo:

Ah, that's my bad for the example. I get the same error from the root, though.

I do have a sparse checkout, so I could try cloning the whole thing. (I resolved all of the issues reported earlier in the test step though 🤔)

@noahtallen
Copy link
Contributor Author

No, same error on master even after doing a full checkout and npm i for root and all packages which needed it. Maybe a permissions issue or an issue running it in a fork? (the fork is up to date)

@noahtallen
Copy link
Contributor Author

noahtallen commented Oct 4, 2021

I actually get a lot more error output on macOS, though this is still a sparse checkout:

~/source/DefinitelyTyped(master) » npm test @wordpress/components

> definitely-typed@0.0.3 test
> dtslint types "@wordpress/components"

tar: Error opening archive: Failed to open '@wordpress/components-14.0.0.tgz'
Error: /Users/noahtallen/source/DefinitelyTyped/types/wordpress__components/color-picker/index.d.ts:2:28
ERROR: 2:28     expect  TypeScript@4.5 compile error:
Cannot find module 'tinycolor2' or its corresponding type declarations.

/Users/noahtallen/source/DefinitelyTyped/types/wordpress__components/custom-select-control/index.d.ts:2:28
ERROR: 2:28     expect  TypeScript@4.5 compile error:
Cannot find module 'downshift' or its corresponding type declarations.

/Users/noahtallen/source/DefinitelyTyped/types/wordpress__components/higher-order/with-focus-outside/index.d.ts:1:27
ERROR: 1:27     expect  TypeScript@4.5 compile error:
Cannot find module '@wordpress/element' or its corresponding type declarations.

/Users/noahtallen/source/DefinitelyTyped/types/wordpress__components/resizable-box/index.d.ts:2:32
ERROR: 2:32     expect  TypeScript@4.5 compile error:
Cannot find module 're-resizable' or its corresponding type declarations.

/Users/noahtallen/source/DefinitelyTyped/types/wordpress__components/slot-fill/context.d.ts:1:27
ERROR: 1:27     expect  TypeScript@4.5 compile error:
Cannot find module '@wordpress/element' or its corresponding type declarations.

/Users/noahtallen/source/DefinitelyTyped/types/wordpress__components/wordpress__components-tests.tsx:2:27
ERROR: 2:27     expect  TypeScript@4.5 compile error:
Cannot find module '@wordpress/element' or its corresponding type declarations.
ERROR: 211:15   expect  TypeScript@4.5 compile error:
Parameter 'v' implicitly has an 'any' type.
ERROR: 1035:9   expect  TypeScript@4.5 compile error:
Argument of type 'typeof (Anonymous class)' is not assignable to parameter of type 'HFOComponent<any, any>'.
  Type '(Anonymous class)' is missing the following properties from type 'Component<any, any, any>': context, setState, forceUpdate, props, and 2 more.
ERROR: 1040:35  expect  TypeScript@4.5 compile error:
Property 'props' does not exist on type '(Anonymous class)'.
ERROR: 1051:31  expect  TypeScript@4.5 compile error:
Property 'props' does not exist on type 'PredefinedComponentClass'.
ERROR: 1054:65  expect  TypeScript@4.5 compile error:
Argument of type 'typeof PredefinedComponentClass' is not assignable to parameter of type 'HFOComponent<any, any>'.
  Type 'PredefinedComponentClass' is missing the following properties from type 'Component<any, any, any>': context, setState, forceUpdate, props, and 2 more.

    at /Users/noahtallen/source/DefinitelyTyped/node_modules/dtslint/bin/index.js:207:19
    at Generator.next (<anonymous>)
    at fulfilled (/Users/noahtallen/source/DefinitelyTyped/node_modules/dtslint/bin/index.js:6:58)

@noahtallen
Copy link
Contributor Author

noahtallen commented Oct 4, 2021

But after resolving those issues (npm i and adding the missing type/ directories), still getting the same error on mac:

~/source/DefinitelyTyped(master) » npm test @wordpress/components

> definitely-typed@0.0.3 test
> dtslint types "@wordpress/components"

tar: Error opening archive: Failed to open '@wordpress/components-14.0.0.tgz'

super weird!

@noahtallen noahtallen changed the title npm test fails with namespaced package npm test fails when opening archive Oct 4, 2021
@lobsterkatie
Copy link
Contributor

I am getting similar errors on Mac OS:

image

Then when I npm install --save-dev webpack @types/webpack and try again:

image

(I ran this with yarn just out of habit, but I tried it with npm as well and got the same result.)

@peterblazejewicz
Copy link
Member

I am getting similar errors on Mac OS:

this is different problem. When testing locally, there is no CI script that install all nested dependencies. One is expected to do this oneself. Here I would usually go to:

cd types/webapck
npm i --no-package-lock

and for any dependency for current test, that is required to be installed from some types/.../package.json
It seems to have no relation to a problem reported by OP initially

@noahtallen
Copy link
Contributor Author

It seems to have no relation to a problem reported by OP initially

I agree -- while I did get those errors, after installing the nested dependencies, those errors go away and I'm left with the thing about tar.

@noahtallen
Copy link
Contributor Author

I'm on another machine now, and I was really hoping it would start working, as I've set the repo up from scratch again!

Still getting this error:

$ npm test '@wordpress/data-controls'

> definitely-typed@0.0.3 test
> dtslint types "@wordpress/data-controls"

tar (child): @wordpress/data-controls-2.2.6.tgz: Cannot open: No such file or directory
tar (child): Error is not recoverable: exiting now
tar: Child returned status 2
tar: Error is not recoverable: exiting now

@noahtallen
Copy link
Contributor Author

noahtallen commented Nov 11, 2021

It's creating a tar file and then trying to access it with the incorrect name:

~/source/DefinitelyTyped wp-data-controls-2.2.6
$ npm test @wordpress/data-controls

> definitely-typed@0.0.3 test
> dtslint types "@wordpress/data-controls"

tar (child): @wordpress/data-controls-2.2.6.tgz: Cannot open: No such file or directory
tar (child): Error is not recoverable: exiting now
tar: Child returned status 2
tar: Error is not recoverable: exiting now

~/source/DefinitelyTyped wp-data-controls-2.2.6 6s
$ ls
azure-pipelines.yml  notNeededPackages.json  README.ja.md  README.ru.md
dangerfile.ts        package.json            README.ko.md  README.zh.md
LICENSE              README.es.md            README.md     types
node_modules         README.it.md            README.pt.md  wordpress-data-controls-2.2.6.tgz

@noahtallen
Copy link
Contributor Author

I think I've narrowed it down to the npm-naming rule. It makes sense, as I assume that will try to match the types package name to the npm package name. Will keeping looking!

@noahtallen
Copy link
Contributor Author

@noahtallen
Copy link
Contributor Author

The tarball name here: https://github.com/DefinitelyTyped/dts-critic/blob/b079c11437c03a6b9d68a95ba2b2872b80201a9c/index.ts#L320

is definitely incorrect. It is considered @wordpres/foo.tar.gz, but the actual downloaded file is wordpress/foo.tar.gz

@noahtallen
Copy link
Contributor Author

Yeah, npm pack shows the wrong file name. As you can see, it downloads it as foo, but the filename says @foo.

~/source/DefinitelyTyped wp-data-controls-2.2.6*
$ ls
azure-pipelines.yml     node_modules            README.it.md  README.ru.md
dangerfile.ts           notNeededPackages.json  README.ja.md  README.zh.md
definitely-typed@0.0.3  package                 README.ko.md  types
dtslint                 package.json            README.md
LICENSE                 README.es.md            README.pt.md

~/source/DefinitelyTyped wp-data-controls-2.2.6*
$ npm pack "@wordpress/data-controls"
npm notice
npm notice 📦  @wordpress/data-controls@2.2.6
npm notice === Tarball Contents ===
npm notice 1.2kB  CHANGELOG.md
npm notice 36.4kB LICENSE.md
npm notice 2.8kB  README.md
npm notice 3.7kB  build-module/index.js
npm notice 5.7kB  build-module/index.js.map
npm notice 4.1kB  build/index.js
npm notice 5.5kB  build/index.js.map
npm notice 969B   package.json
npm notice 3.6kB  src/index.js
npm notice 664B   src/test/index.js
npm notice === Tarball Details ===
npm notice name:          @wordpress/data-controls
npm notice version:       2.2.6
npm notice filename:      @wordpress/data-controls-2.2.6.tgz
npm notice package size:  17.6 kB
npm notice unpacked size: 64.6 kB
npm notice shasum:        fb927cd060dbd08e56661c153278746c2d16d195
npm notice integrity:     sha512-voh/MjwThLZGO[...]C/yQSiZMKo5ZA==
npm notice total files:   10
npm notice
wordpress-data-controls-2.2.6.tgz

~/source/DefinitelyTyped wp-data-controls-2.2.6*
$ ls
azure-pipelines.yml     package       README.pt.md
dangerfile.ts           package.json  README.ru.md
definitely-typed@0.0.3  README.es.md  README.zh.md
dtslint                 README.it.md  types
LICENSE                 README.ja.md  wordpress-data-controls-2.2.6.tgz
node_modules            README.ko.md
notNeededPackages.json  README.md

@noahtallen
Copy link
Contributor Author

There's even an existing issue: npm/cli#3405

@noahtallen
Copy link
Contributor Author

A workaround is to use an older npm version, such as v6.14.15.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants