-
-
Notifications
You must be signed in to change notification settings - Fork 558
Open
Labels
Description
What happened: I was working on a simple project that used MJS import/export to load the express
module rather than require. It worked perfectly fine via npm start
, but when I built it with nexe it crashed with this error:
Error: Cannot find package 'C:\Users\...\bin\node_modules\express\package.json' imported from C:\Users\...\bin\src\App.js
Did you mean to import "express/index.js"?
at legacyMainResolve (node:internal/modules/esm/resolve:215:26)
at packageResolve (node:internal/modules/esm/resolve:841:14)
at moduleResolve (node:internal/modules/esm/resolve:927:18)
at defaultResolve (node:internal/modules/esm/resolve:1157:11)
at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:383:12)
at ModuleLoader.resolve (node:internal/modules/esm/loader:352:25)
at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:227:38)
at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:87:39)
at link (node:internal/modules/esm/module_job:86:36)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
The exact same issue seems to happen with any module loaded by legacyMainResolve, when imported as follows:
import <package> from "<package name>";
However, it works perfectly if imported like this:
import <package> from "<package name>/index.js";
What you expected to happen: I expected for the import to be resolved correctly to index.js
, rather than package.json
.
How to reproduce it (as minimally and precisely as possible):
- Create a new project using
npm init
andnpm i express
- Add the line
"type": "module",
to yourpackage.json
- Create the file
index.js
and add the following to it
import express from "express";
const app = express();
console.log("loaded");
- Build and run it with nexe using the following commands:
nexe -i index.js --build -o bin/out.exe
cd bin
./out.exe
- The package fails to load
- Replace line 1 of
index.js
withimport express from "express/index.js";
- Repeat step 4
- The package loads perfectly
Environment:
- Platform(OS/Version): Windows 11 23H2 (OS Build 22631.4317)
- Host Node Version: v20.14.0
- Target Node Version: v20.14.0
- Nexe version: 5.0.0-beta.3 (I couldn't get v4 working at all)
- Python Version: 3.12.6
KitaPDev, Bacto and dakanggo