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
- A clean build of the package (run your build script first).
- An empty scratch directory outside the repository, so nothing resolves back to your source by accident.
- Five to ten minutes. This is a smoke test, not a second test suite.
Steps for an npm package
- 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.envfiles, test fixtures or source maps you did not intend to ship. - If the list is wrong, fix the
filesarray inpackage.json. An allowlist is safer than an.npmignoredenylist because new files are excluded by default. - Create the real tarball with
npm pack. It writes a.tgznamed after the package and version. - In the scratch directory, run
npm init -yand thennpm install /path/to/example-lib-1.2.0.tgz. - Write a three-line script that imports the package and calls one public function. Run it.
Steps for a Python package
- Build both distributions:
python -m buildproduces an sdist and a wheel indist/. - Run
twine check dist/*to validate the metadata and confirm the long description will render. - Open the wheel's file list (
unzip -l dist/*.whl) and check that your package directory, any data files and thepy.typedmarker, if you ship type hints, are present. - 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__)". - 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 project | Usual cause |
|---|---|
| Module not found | Build output missing from files or the wheel's package list |
| Import works, types missing | Declarations not shipped, or the types path is wrong |
| Works here, fails on another OS | Case-sensitive filename mismatch in an import |
| Unexpectedly large install | Fixtures, 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.