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

How to make it run in PKG ? #96

Closed
fengcms opened this issue Apr 28, 2020 · 1 comment
Closed

How to make it run in PKG ? #96

fengcms opened this issue Apr 28, 2020 · 1 comment

Comments

@fengcms
Copy link

fengcms commented Apr 28, 2020

Test project file tree:

├── config
│   └── index.js
└── index.js

Code of index.js

require('module-alias/register')
const { A, B } = require(':config')
console.log(A, B)

Code of config/index.js

module.exports = {
  A: 1,
  B: 2
}

Config in package.json

  "_moduleAliases": {
    ":config": "config"
  }

It's work in nodejs, print this:

$ node index.js
1 2

but, if I run this pkg index.js, print this:

$ pkg index.js
> [email protected]
> Targets not specified. Assuming:
  node10-linux-x64, node10-macos-x64, node10-win-x64
> Warning Cannot find module ':config' from '/Users/fungleo/Sites/Github/npm-test'
  %1: /Users/fungleo/Sites/Github/npm-test/index.js

so.... I want cry...some one help me?

@Kehrlann
Copy link
Collaborator

Hi @fengcms !

So, I won't investigate in depth, but last time someone tried to use module-alias with zeit/ncc, that was not possible. So I'm guessing it's not working for the same reason. If you want more details, see issue #81 .

However, there's a silver lining - you can configure some sort of aliases in pkg too. Not sure if you can make it work, but worth giving it a try: https://github.com/zeit/pkg#config

Not much we can do from module-alias, so I'll close this issue.

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