vercel / pkg

Package your Node.js project into an executable
https://npmjs.com/pkg
MIT License
24.33k stars 1.02k forks source link

Module-Alias not working with pkg #2002

Closed avinashk2946 closed 10 months ago

avinashk2946 commented 1 year ago

What version of pkg are you using?

5.8.1

What version of Node.js are you using?

18.16.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

Describe the Bug

I am using plain JavaScript for building APIs using Node.js and Express.js. I have the following module alias configuration, which is heavily used across my project in require statements:


const moduleAlias = require("module-alias"),
  path = require("path"),
  root = path.join(__dirname, "../"),
  api = `${root}/src`,
  aliasConfig = {
    "@root": root,
    "@custom-lib": `${root}/custom-lib`,
    "@api": api
  };

global.baseDir = root;

module.exports = () => moduleAlias.addAliases(aliasConfig);

I'm getting the following error after running the pkg . command:

Warning Cannot find module '@root/routes' from 'C:\Workspace\Projects\server.js'

It seems that the module alias configuration is causing an issue when trying to find the @root/routes module. Any suggestions on how to resolve this would be greatly appreciated.

Expected Behavior

The require statements should not throw error.

To Reproduce

Just create a project with module-alias configuration and then run the pkg commands.

Module Alias NPM

avinashk2946 commented 1 year ago

@wentsul @trek @rauchg @tomocchino : Can you please help