nodejs / single-executable

This team aims to advance the state of the art in packaging Node.js applications as single standalone executables (SEAs) on all supported operating systems.
317 stars 6 forks source link

Error [ERR_UNKNOWN_BUILTIN_MODULE]: No such built-in module: express #87

Open MGMehdi opened 10 months ago

MGMehdi commented 10 months ago

Hello, I tried to compile my express app following the Single executable applications guide in but I've got this error :

node:internal/util/embedding:48
    throw new ERR_UNKNOWN_BUILTIN_MODULE(id);
    ^

Error [ERR_UNKNOWN_BUILTIN_MODULE]: No such built-in module: express
    at embedderRequire (node:internal/util/embedding:48:11)
    at dist/app.js:141:33
    at embedderRunCjs (node:internal/util/embedding:37:10)
    at node:internal/main/embedding:18:8 {
  code: 'ERR_UNKNOWN_BUILTIN_MODULE'
}

Node.js v21.6.0

It also appear with Node.js v20.10.0.

The app is written with typescript but the build is working when running in the terminal. Here is the tsconfig.json

{
  "compilerOptions": {
    "target": "ES5",
    "lib": ["ES5"],
    "module": "commonjs",
    "rootDir": "./src",
    "sourceMap": true,
    "outDir": "./dist",
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "strict": true,
    "skipLibCheck": true
  }
}

Did I miss something ?

GabenGar commented 10 months ago

Yeah, the part where it says that it only supports built-in modules.

joyeecheung commented 10 months ago

Yes, for now you would need to bundle your code into one single file that only requires builtins before injecting it into the SEA.

MGMehdi commented 10 months ago

Hooo I didn't understand like that. Thanks for the clarification! For now if I want to achieve the same results is by using pkg by vercel?

robertsLando commented 10 months ago

FYI pkg has been archived now. I'm maintaining the most active fork here: https://github.com/yao-pkg/pkg

If you need ESM support there some alternatives: https://github.com/yao-pkg/pkg/issues/16#issuecomment-1945486658

pironev commented 7 months ago

This will works if you do a build with just one file. Install esbuild: npm install --save-exact --save-dev esbuild Copy to package.json:

     "scripts": {
     "build": "esbuild your-start-file.js --bundle --platform=node --outfile=out.js"
        }

generate out.js : npm run build Then resumes the whole process from https://nodejs.org/api/single-executable-applications.html for out.js

Cycov commented 6 months ago

This will works if you do a build with just one file. Install esbuild: npm install --save-exact --save-dev esbuild Copy to package.json:

     "scripts": {
     "build": "esbuild your-start-file.js --bundle --platform=node --outfile=out.js"
        }

generate out.js : npm run build Then resumes the whole process from https://nodejs.org/api/single-executable-applications.html for out.js

In my case I need to package a application that uses the serialport module. The compiled version throws the following error: Error: No native build was found for platform=win32 arch=x64 runtime=node abi=127 uv=1 libc=glibc node=22.2.0

robertsLando commented 6 months ago

@Cycov check https://github.com/zwave-js/zwave-js-ui/blob/master/esbuild.js

BillChen-AI commented 5 months ago

This will works if you do a build with just one file. Install esbuild: npm install --save-exact --save-dev esbuild Copy to package.json:

     "scripts": {
     "build": "esbuild your-start-file.js --bundle --platform=node --outfile=out.js"
        }

generate out.js : npm run build Then resumes the whole process from https://nodejs.org/api/single-executable-applications.html for out.js

I followed the steps you provided and successfully resolved a fast-csv built-in module not found issue. The generated exe runs without an error on Windows 10 64-bit.

codenoid commented 2 months ago

@robertsLando I've tried your esbuild.js file, but it's not works for me :(, I'm having issue with usb package