How to Test the Packed Artefact Before You Publish

Your test suite runs against the source tree. Your users install a tarball or a wheel. Those are not the same thing, and the gap between them is where "Cannot find module" bug reports come from. This how-to shows a quick routine for testing the exact file you are about to upload.

What you need

Steps for an npm package

  1. List what would be published without creating anything: npm pack --dry-run. Read the file list. Look for missing build output, and for things that should not be there, such as .env files, test fixtures or source maps you did not intend to ship.
  2. If the list is wrong, fix the files array in package.json. An allowlist is safer than an .npmignore denylist because new files are excluded by default.
  3. Create the real tarball with npm pack. It writes a .tgz named after the package and version.
  4. In the scratch directory, run npm init -y and then npm install /path/to/example-lib-1.2.0.tgz.
  5. Write a three-line script that imports the package and calls one public function. Run it.

Steps for a Python package

  1. Build both distributions: python -m build produces an sdist and a wheel in dist/.
  2. Run twine check dist/* to validate the metadata and confirm the long description will render.
  3. Open the wheel's file list (unzip -l dist/*.whl) and check that your package directory, any data files and the py.typed marker, if you ship type hints, are present.
  4. Create a fresh virtual environment in the scratch directory, install the wheel by path, and run python -c "import example_lib; print(example_lib.__version__)".
  5. Repeat with the sdist. Building from the sdist is where missing files in the source distribution tend to show up.

What this catches

Symptom in the scratch projectUsual cause
Module not foundBuild output missing from files or the wheel's package list
Import works, types missingDeclarations not shipped, or the types path is wrong
Works here, fails on another OSCase-sensitive filename mismatch in an import
Unexpectedly large installFixtures, docs or media included by accident

How to check it worked

The routine has worked when the scratch project imports the package, calls a public function successfully and you can explain every file in the artefact's listing. Once it passes by hand, move the same steps into CI as a job that runs before the publish job. Then every release is tested in the form users receive it, not only in the form you wrote it.

Related pages