pnpm publish not respecting "files" field in package.json

328 Views Asked by At

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

1

There are 1 best solutions below

1
On BEST ANSWER

If both pnpm pack and npm pack reports correct files, nothing is wrong with respect to the files field in package.json.

Your zod-to-fields directory is probably a symlink to your local project directory created from running pnpm link, so that's why you see all files.

In your consumer project on your machine you need to unlink the dependency to remove the symlink and install it as a proper dependency from the package repository:

cd consumer-of-zod
pnpm unlink zod-to-fields