pnpm publish not respecting “files” field in package.json

I’ve encountered an odd behavior with pnpm when publishing my package. Even though I’ve clearly specified the “files” field in my package.json, it seems that pnpm is bundling all files from my project into the published package.

Here’s a snippet of my package.json:

"files": [
  "build",
  "README.md",
  "LICENSE"
]

After publishing and installing my package, I noticed that the node_modules directory for my package contains a complete 1:1 copy of all my project files, rather than just the specified build, README.md, and LICENSE.

Steps I’ve tried to resolve this:

Made sure the build output is correctly placed in the build directory.

Checked the package content using npm pack.

Ignore all files ‘*’, ignore specific files, etc. everything is included anyway

Yet, the issue still persists. Has anyone here experienced this with pnpm? I’d really appreciate any insights or advice to fix this. Thanks in advance!

in npm it seems to work fine

https://www.npmjs.com/package/zod-to-fields?activeTab=code

but once i install it in any project i can see whole project

im publishing my package with flag –access public

pnpm pack generete tgz file with files included only in files packagejson so I have no idea why it wokrs like that
enter image description here

Leave a Comment