This repository was archived by the owner on Jan 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
This repository was archived by the owner on Jan 13, 2024. It is now read-only.
Compiling fails with subpath imports #1674
Copy link
Copy link
Closed
Labels
Description
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 inpackage.json
- Import something using the imports entry in the script that you are trying to compile
- Compile
wkrasnicki-vizlib