Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkg fails to respect the exports fields #56

Closed
derevnjuk opened this issue Apr 17, 2024 · 4 comments
Closed

pkg fails to respect the exports fields #56

derevnjuk opened this issue Apr 17, 2024 · 4 comments

Comments

@derevnjuk
Copy link

derevnjuk commented Apr 17, 2024

What version of pkg are you using?

5.11.5

What version of Node.js are you using?

18.20.2

What operating system are you using?

macOS

What CPU architecture are you using?

x86_64

What Node versions, OSs and CPU architectures are you building for?

node18

Describe the Bug

When attempting to package a Node.js application that uses the axios library (version 1.6.3), the pkg command fails to create functional single executable and issues warnings about not being able to generate bytecode for axios files.

Steps to Reproduce:

  1. Include axios version 1.6.3 in your project's dependencies.
  2. Utilize axios in your application.
  3. Run the packaging command: pkg . -t node18-macos-x64.

Similar tickets: vercel#2042 and vercel#1873

Expected Behavior

The application should be successfully packaged into binaries as specified in the main and exports fields the package.json

To Reproduce

The single executables are created, and the following warnings are displayed:

> Warning Failed to make bytecode node18-x64 for file /snapshot/bright-cli/node_modules/axios/lib/platform/node/classes/URLSearchParams.js
> Warning Failed to make bytecode node18-x64 for file /snapshot/bright-cli/node_modules/axios/lib/helpers/throttle.js

However, while running the single executable, it prints the following error message:

Error: Cannot find module '/snapshot/bright-cli/node_modules/axios/dist/node/axios.cjs'
1) If you want to compile the package/file into executable, please pay attention to compilation warnings and specify a literal in 'require' call. 2) If you don't want to compile the package/file into executable and want to 'require' it from filesystem (likely plugin), specify an absolute path in 'require' call using process.cwd() or process.execPath.
    at createEsmNotFoundErr (node:internal/modules/cjs/loader:1171:15)
    at finalizeEsmResolution (node:internal/modules/cjs/loader:1159:15)
    at resolveExports (node:internal/modules/cjs/loader:584:14)
    at Module._findPath (node:internal/modules/cjs/loader:658:31)
    at Module._resolveFilename (node:internal/modules/cjs/loader:1120:27)
    at Function._resolveFilename (pkg/prelude/bootstrap.js:1955:46)
    at Module._load (node:internal/modules/cjs/loader:975:27)
    at Module.require (node:internal/modules/cjs/loader:1225:19)
    at Module.require (pkg/prelude/bootstrap.js:1851:31)
    at require (node:internal/modules/helpers:177:18) {
  code: 'MODULE_NOT_FOUND',
  path: '/snapshot/bright-cli/node_modules/axios/package.json',
  pkg: true
}

@robertsLando
Copy link
Member

This is a known bug, see #16

@derevnjuk
Copy link
Author

@robertsLando I see. However, Axios, like many other dependencies, uses the exports field to declare multiple artifacts for both CommonJS and ESM. Adding support for ESM does not resolve the issue with loading CommonJS entries declared in the exports field.

@robertsLando
Copy link
Member

see the comment: #16 (comment)

@derevnjuk
Copy link
Author

@robertsLando I see. Thanks 🙏🏾

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

No branches or pull requests

2 participants