Skip to content

Docs: list which Node built-in modules are allowed vs blocked at runtime #147

Description

@jonathanrobie

Problem

Platform.Bible's extension host blocks most Node built-ins at runtime with:

Error: Requiring other than papi is not allowed in extensions! Rejected require('fs').
Try using papi.storage or bundling the module into your code with a build tool like webpack

The webpack config comment in webpack.config.base.ts mentions a wiki page on module import restrictions but does not state which built-ins are allowed. Developers naturally add blocked modules to externals (because webpack accepts them without complaint), only to hit a runtime crash after a successful build.

Currently crypto is listed in externals as the one allowed built-in, but there is no list of what else is or isn't available.

Suggested Improvements

  1. Add a comment to webpack.config.base.ts next to the externals array:
// Built-in Node modules available at runtime (all others are blocked):
// - crypto
// Do NOT add fs, os, path, etc. — they will compile fine but crash at runtime.
'crypto',
  1. Add a section to the wiki page on module import restrictions listing:
    • Which Node built-ins are available
    • The recommended alternative for common patterns (e.g. papi.storage instead of fs, papi.network instead of raw http)

Context

Discovered while implementing port-file discovery in paratext-copilot. Added fs and os to externals, got a clean build, then hit a runtime crash. The fix (remove them and use fetch-based probing instead) was non-obvious.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions