ES module resolution fails when "type": "module" is set into the package.json and the resolution is being done only depending on "main" field into the package.json
And here's the error I get from electron-builder when packaging the app:
⨯ require() of ES Module /Users/**/**/**/desktop-application/dist/main/main.js from /Users/**/**/**/node_modules/.pnpm/app-builder-lib@24.10.0/node_modules/app-builder-lib/out/platformPackager.js not supported.
Instead change the require of main.js in /Users/**/**/**/node_modules/.pnpm/app-builder-lib@24.10.0/node_modules/app-builder-lib/out/platformPackager.js to a dynamic import() which is available in all CommonJS modules. failedTask=build stackTrace=Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/**/**/**/desktop-application/dist/main/main.js from /Users/**/**/**/node_modules/.pnpm/app-builder-lib@24.10.0/node_modules/app-builder-lib/out/platformPackager.js not supported.
Instead change the require of main.js in /Users/**/**/**/node_modules/.pnpm/app-builder-lib@24.10.0/node_modules/app-builder-lib/out/platformPackager.js to a dynamic import() which is available in all CommonJS modules.
at resolveModule (/Users/**/**/**/node_modules/.pnpm/app-builder-lib@24.10.0/node_modules/app-builder-lib/out/platformPackager.js:596:17)
at resolveFunction (/Users/**/**/**/node_modules/.pnpm/app-builder-lib@24.10.0/node_modules/app-builder-lib/out/platformPackager.js:614:21)
at MacPackager.doSignAfterPack (/Users/**/**/**/node_modules/.pnpm/app-builder-lib@24.10.0/node_modules/app-builder-lib/out/platformPackager.js:253:33)
at async MacPackager.doPack (/Users/**/**/**/node_modules/.pnpm/app-builder-lib@24.10.0/node_modules/app-builder-lib/out/platformPackager.js:238:13)
at async MacPackager.pack (/Users/**/**/**/node_modules/.pnpm/app-builder-lib@24.10.0/node_modules/app-builder-lib/out/macPackager.js:157:17)
at async Packager.doBuild (/Users/**/**/**/node_modules/.pnpm/app-builder-lib@24.10.0/node_modules/app-builder-lib/out/packager.js:360:17)
at async executeFinally (/Users/**/**/**/node_modules/.pnpm/builder-util@24.9.4/node_modules/builder-util/out/promise.js:14:18)
at async Packager._build (/Users/**/**/**/node_modules/.pnpm/app-builder-lib@24.10.0/node_modules/app-builder-lib/out/packager.js:306:35)
at async Packager.build (/Users/**/**/**/node_modules/.pnpm/app-builder-lib@24.10.0/node_modules/app-builder-lib/out/packager.js:277:16)
at async executeFinally (/Users/**/**/**/node_modules/.pnpm/builder-util@24.9.4/node_modules/builder-util/out/promise.js:14:18)
After a little bit of debugging into the platformPackager.js part in the function "resolveModule(type, name)", here's the output:
Which means that the if condition will never be executed properly and that it defaults to the commonjs require instead of evaluating the dynamic import added recently in the following pull request
ES module resolution fails when "type": "module" is set into the package.json and the resolution is being done only depending on "main" field into the package.json
Here's my package.json:
And here's the error I get from electron-builder when packaging the app:
After a little bit of debugging into the platformPackager.js part in the function "resolveModule(type, name)", here's the output:
Which means that the if condition will never be executed properly and that it defaults to the commonjs require instead of evaluating the dynamic import added recently in the following pull request