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

Support for axios missing #30

Closed
issamBenelgada opened this issue Feb 12, 2024 · 2 comments
Closed

Support for axios missing #30

issamBenelgada opened this issue Feb 12, 2024 · 2 comments

Comments

@issamBenelgada
Copy link

issamBenelgada commented Feb 12, 2024

What version of pkg are you using?

5.8.1

What version of Node.js are you using?

18.19.0

What operating system are you using?

Windows

What CPU architecture are you using?

x86_64

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

node18-windows-x64

Describe the Bug

I'm getting this error when executing my packaged project that uses axios.

pkg/prelude/bootstrap.js:1872
      throw error;
      ^

Error: Cannot find module 'C:\snapshot\my-app\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:967:15)
    at finalizeEsmResolution (node:internal/modules/cjs/loader:960:15)
    at resolveExports (node:internal/modules/cjs/loader:488:14)
    at Module._findPath (node:internal/modules/cjs/loader:528:31)
    at Module._resolveFilename (node:internal/modules/cjs/loader:932:27)
    at Function._resolveFilename (pkg/prelude/bootstrap.js:1951:46)
    at Module._load (node:internal/modules/cjs/loader:787:27)
    at Module.require (node:internal/modules/cjs/loader:1012:19)
    at Module.require (pkg/prelude/bootstrap.js:1851:31)
    at require (node:internal/modules/cjs/helpers:102:18) {
  code: 'MODULE_NOT_FOUND',
  path: 'C:\\snapshot\\my-app\\node_modules\\axios\\package.json',
  pkg: true
}

Node.js v18.5.0

I belive the problem is that pkg only packages the esm code of axios and not the whole folder, but my project is in commonJS.
This is part of the package.json file of the axios package.

{
  "name": "axios",
  "version": "1.6.3",
  "description": "Promise based HTTP client for the browser and node.js",
  "main": "index.js",
  "exports": {
    ".": {
      "types": {
        "require": "./index.d.cts",
        "default": "./index.d.ts"
      },
      "browser": {
        "require": "./dist/browser/axios.cjs",
        "default": "./index.js"
      },
      "default": {
        "require": "./dist/node/axios.cjs",
        "default": "./index.js"
      }
    },
...

The main points to index.js and as nothing requires dist/node/axios.cjs it's not included in the final package.
To import the package in my code I use require(axios).

I was able to fix the problem by adding a new dictionary file for axios : axios.js :

'use strict';

module.exports = {
  pkg: {
    scripts: ['dist/**/*'],
  },
};

This did solve my problem and I was hoping it could be added in a future version.

Expected Behavior

Application runs without errors using axios module in a common js project.

To Reproduce

Create a new common js node project with axios as a dependency.

Package project using pkg and run the packaged application.

@robertsLando
Copy link
Member

robertsLando commented Feb 13, 2024

Same as #10. Include all the axios node modules in scripts/assets in order to make it work

@robertsLando
Copy link
Member

Dup of #16 (comment)

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