Hi,
I’m encountering the following runtime error only during performance testing:
pm.require is not a function
This does not occur during manual request execution.
Context and Setup
To isolate the issue, I’ve set up a minimal script that uses pm.require()
to import internal team’s Postman package (name is changed in the post):
Pre-request Script (on the collection):
pm.request.headers.upsert({ key: 'Before-Require', value: 'test' });
try {
const package = pm.require('@team/package');
pm.request.headers.upsert({ key: 'Require-Success', value: 'yes' });
} catch (err) {
pm.request.headers.upsert({ key: 'Require-Error', value: err.message });
}
pm.request.headers.upsert({ key: 'After-Require', value: 'test' });
Request URL (invalid on purpose to inspect headers in performance test):
http://{empty-variable}/
Observed Behavior
-
Manual execution:
The request runs successfully, and the uuid
module is imported without errors.
-
Performance test execution:
The error "pm.require is not a function"
is caught and inserted into the request headers.
Is pm.require()
unsupported in the performance test runtime environment?
If so, is there an alternative way to use libraries in performance test scripts?
Thank you in advance.
pm.require() is not supported in the Postman Performance Testing (formerly called “Runner” or “Collection Runner”) runtime environment.
If you want a workaround I will help you
1 Like
Thanks for the info. I assume that workaround is inserting implementation of all needed functions at the beginning of the script.
As a workaround, you should directly include any essential utility code or functions within your pre-request or test scripts, rather than importing them as external packages. This means copying and pasting the relevant logic from your internal library into the script so it runs natively in the restricted sandbox. While this approach may not be as modular or maintainable as using packages, it ensures compatibility with the performance test runtime and allows your scripts to execute successfully without dependency errors. For more complex scenarios, consider refactoring your scripts to minimize reliance on external libraries or handle such logic outside of Postman before tests are run.
You need to be careful with scripting on performance tests, as the scripts still take some time to execute and could potentially skew the results.
I’ve not used the performance tools in Postman to see whether the reports breaks down the run to show any potentially time taken by scripts.
I would still keep code like assertions to a minimum.
2 Likes