After updating to Node 20 ,using PKG executable issue

264 Views Asked by At

I am using @yao-pkg/[email protected] to package our application to exe file,when i tried with the node 20version ,using this command pkg -t node20-win . .I am getting the executable but when i try to run the application i am getting the below error.

Our application is using typescript + nodejs

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

Error [ERR_REQUIRE_ESM]: require() of ES Module C:\snapshot\backend\bundle\app.js not supported. app.js is treated as an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which declares all .js files in that package scope as ES modules. Instead either rename app.js to end in .cjs, change the requiring code to use dynamic import() which is available in all CommonJS modules, or change "type": "module" to "type": "commonjs" in C:\snapshot\backend\package.json to treat all .js files as CommonJS (using .mjs for all ES modules instead).

at Function.runMain (pkg/prelude/bootstrap.js:1983:12) {

code: 'ERR_REQUIRE_ESM' }

Node.js v20.11.1

1

There are 1 best solutions below

0
Pankaj On

Bundling all code files into single js file can solve this issue

Check this discussion for more info:

https://github.com/vercel/pkg/issues/782