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

[BUG] npm pkg fix does not fix invalid scripts warning. #7127

Closed
2 tasks done
everett1992 opened this issue Jan 11, 2024 · 1 comment · Fixed by npm/package-json#102
Closed
2 tasks done

[BUG] npm pkg fix does not fix invalid scripts warning. #7127

everett1992 opened this issue Jan 11, 2024 · 1 comment · Fixed by npm/package-json#102
Assignees
Labels
Bug thing that needs fixing Priority 2 secondary priority issue Release 10.x

Comments

@everett1992
Copy link

everett1992 commented Jan 11, 2024

Is there an existing issue for this?

  • I have searched the existing issues

This issue exists in the latest npm version

  • I am using the latest npm

Current Behavior

When publishing a package without scripts npm will warn that the errors were corrected in the published package.json, and that they can be fixed in the source package json with npm pkg fix.

npm WARN publish npm auto-corrected some errors in your package.json when publishing.  Please run "npm pkg fix" to address these errors.
npm WARN publish errors corrected:
npm WARN publish Removed invalid "scripts"

However, running npm pkg fix does not make any changes to package.json and publishing will print the same warning.

The "Removed invalid "scripts"" warning has been discussed and closed before. I think they were closed because npm maintainers justified the warning, but the ineffective advice to run npm pkg fix has not been addressed.

#6918
#6887

Expected Behavior

npm pkg fix should add "scripts": {} to package.json, or the warning should be removed for scripts.

Steps To Reproduce

~/tmp » cat package.json
{
  "name": "tmp",
  "version": "1.0.0"
}

~/tmp » npx npm@10.3.0 publish --dry-run
npm WARN publish npm auto-corrected some errors in your package.json when publishing.  Please run "npm pkg fix" to address these errors.
npm WARN publish errors corrected:
npm WARN publish Removed invalid "scripts"
npm notice
npm notice 📦  tmp@1.0.0
npm notice === Tarball Contents ===
npm notice 42B  package.json
npm notice 41B  ws/package.json
npm notice 138B ws/ws-1.0.0.tgz
npm notice === Tarball Details ===
npm notice name:          tmp
npm notice version:       1.0.0
npm notice filename:      tmp-1.0.0.tgz
npm notice package size:  344 B
npm notice unpacked size: 221 B
npm notice shasum:        26433916c42a0bb86db80fa9b56874a71193607f
npm notice integrity:     sha512-xYYLg2OHl4Syb[...]V0h8JULEXt3Zw==
npm notice total files:   3
npm notice
npm WARN This command requires you to be logged in to https://registry.npmjs.org/ (dry-run)
npm notice Publishing to https://registry.npmjs.org/ with tag latest and default access (dry-run)
+ tmp@1.0.0

~/tmp » npx npm@10.3.0 pkg fix

~/tmp » cat package.json
{
  "name": "tmp",
  "version": "1.0.0"
}

Environment

  • npm: 10.3.0 (and 10.2.30
  • Node.js: N/A (18.19.0)
  • OS Name: Ubuntu
  • System Model Name: What
  • npm config:
; node bin location = ~/.local/share/rtx/installs/node/18.19.0/bin/node
; node version = v18.19.0
; npm local prefix = ~tmp
; npm version = 10.2.3
; cwd = ~/tmp
; HOME = ~/
; Run `npm config ls -l` to show all defaults.
@everett1992 everett1992 added Bug thing that needs fixing Needs Triage needs review for next steps Release 10.x labels Jan 11, 2024
@everett1992
Copy link
Author

It seems like adding scripts to fix steps would fix this issue.
https://github.com/npm/package-json/blob/main/lib/index.js#L32

But npm should probably check if the normalize step that created a change is actually fixable before printing the warning.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug thing that needs fixing Priority 2 secondary priority issue Release 10.x
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants