Skip to content
This repository has been archived by the owner on Jan 13, 2024. It is now read-only.

Compiling fails with subpath imports #1674

Closed
afm-sayem opened this issue Jun 30, 2022 · 4 comments
Closed

Compiling fails with subpath imports #1674

afm-sayem opened this issue Jun 30, 2022 · 4 comments
Labels

Comments

@afm-sayem
Copy link

What version of pkg are you using?

5.7.0

What version of Node.js are you using?

18.2.0

What operating system are you using?

macOS

What CPU architecture are you using?

Apple M1

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

node18

Describe the Bug

https://nodejs.org/api/packages.html#subpath-imports

In my application(esm), I have specified mappings to internal directories so that I can use them easily instead of specifying the full relative path.

package.json

{
  "name": "@testapp/demo",
  "main": "app.js",
  "type": "module",
  "imports": {
    "#lib/*": "./lib/*"
  },
  "scripts": {
    "dev": "DEBUG=knex:query nodemon --experimental-json-modules app",
    "start": "node --experimental-json-modules app.js"
  },
  "engines": {
    "node": ">=18.x.x"
  },
  "dependencies": {
    "@koa/router": "^10.1.1",
    "koa": "^2.13.4",
    "pkg": "^5.7.0"
  }
}

app.js

import 'dotenv/config';
import Koa from 'koa';
import router from '#lib/routes.js';

const app = new Koa();
app.use(router.routes());

const server = app.listen(config.port || 6001, () => {
  console.log('Example app listening at port %s', server.address().port);
});

Command: npx pkg --target node18 app.js

Result:

npx pkg --target node18 app.js
> pkg@5.7.0
> Warning Cannot find module '#lib/routes.js' from '/Users/<user>/projects/<project>/testapp/demo'  in /Users/<user>/projects/<project>/testapp/demo/app.js
> Warning Failed to make bytecode node18-arm64 for file /snapshot/demo/app.js

The application is running correctly using the npm scripts.

A binary is created but when I execute that I'm getting:

node:internal/modules/cjs/loader:942
  throw err;
  ^

Error: Cannot find module '/snapshot/demo/app.js'
....
....

Expected Behavior

Application correctly built

To Reproduce

  • Create an imports entry in package.json
  • Import something using the imports entry in the script that you are trying to compile
  • Compile
@github-actions
Copy link

This issue is stale because it has been open 90 days with no activity. Remove the stale label or comment or this will be closed in 5 days. To ignore this issue entirely you can add the no-stale label

@github-actions github-actions bot added the Stale label Sep 29, 2022
@robertsLando
Copy link
Contributor

pkg doesn't support esm modules #1323

@github-actions github-actions bot removed the Stale label Sep 30, 2022
@github-actions
Copy link

This issue is stale because it has been open 90 days with no activity. Remove the stale label or comment or this will be closed in 5 days. To ignore this issue entirely you can add the no-stale label

@github-actions github-actions bot added the Stale label Dec 30, 2022
@github-actions
Copy link

github-actions bot commented Jan 5, 2023

This issue is now closed due to inactivity, you can of course reopen or reference this issue if you see fit.

@github-actions github-actions bot closed this as completed Jan 5, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants