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

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

Open
MGMehdi opened this issue Jan 17, 2024 · 9 comments
Open

Comments

@MGMehdi
Copy link

MGMehdi commented Jan 17, 2024

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
Copy link

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

@joyeecheung
Copy link
Member

joyeecheung commented Jan 18, 2024

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
Copy link
Author

MGMehdi commented Jan 20, 2024

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
Copy link

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: yao-pkg/pkg#16 (comment)

@pironev
Copy link

pironev commented May 14, 2024

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
Copy link

Cycov commented Jun 4, 2024

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
Copy link

robertsLando commented Jun 4, 2024

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

@BillChen-AI
Copy link

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
Copy link

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

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

8 participants