Skip to content

Conversation

patrickkfkan
Copy link

Currently, pkg uses module.builtinModules for checking core modules, while stripping any node: prefix. The problem is, certain core modules do not appear in builtinModules and can only be checked with module.isBuiltin. An example would be node:sqlite (note: this is a prefix-only module, which must be imported with the prefix intact). I came across this when trying to package my project that uses undici, which imports node:sqlite. Simplest way to illustrate this:

// example.js
const undici = require("undici");

Running:

pkg example.js

will throw:

> Error! Cannot read file, ENOENT
  node:sqlite
> Error! ENOENT: no such file or directory, open 'node:sqlite'

This PR fixes this by using module.isBuiltin if available.

Copy link
Member

@robertsLando robertsLando left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this! We were not able to to understand why this was happening

@robertsLando robertsLando changed the title Prefer module.isBuiltin when checking core modules fix: prefer module.isBuiltin when checking core modules Apr 29, 2025
@robertsLando robertsLando merged commit 3a57036 into yao-pkg:main Apr 30, 2025
47 of 48 checks passed
@TobiWo
Copy link

TobiWo commented May 17, 2025

Thank you so much for bringing this up @patrickkfkan. This solved a big issue for me 🙏 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants