leafac / kill-the-newsletter

Convert email newsletters into Atom feeds
https://kill-the-newsletter.com
MIT License
2.31k stars 113 forks source link

How to compile kill-the-newsletter to exe? #63

Closed ufo512 closed 1 year ago

ufo512 commented 2 years ago

I am able to run kill-the-newsletter locally with node, but I want to compile it to exe to put it on Digital Ocean. I'm on Windows 10. After installing caxa, I tried to make an exe file with this command:

npx caxa --directory . --command "{{caxa}}/node_modules/.bin/node" "{{caxa}}/lib" --output ktn.exe

It created the exe but when I try to run it, it throws an error:

`internal/modules/cjs/loader.js:1089 throw new ERR_REQUIRE_ESM(filename, parentPath, packageJsonPath); ^

Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: C:\Users\Dell\AppData\Local\Temp\caxa\ktn\kerfwv1oby\node_modules\@leafac\html\distribution\index.js require() of ES modules is not supported. require() of C:\Users\Dell\AppData\Local\Temp\caxa\ktn\kerfwv1oby\node_modules\@leafac\html\distribution\index.js from C:\Users\Dell\AppData\Local\Temp\caxa\ktn\kerfwv1oby\lib\index.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules. Instead rename C:\Users\Dell\AppData\Local\Temp\caxa\ktn\kerfwv1oby\node_modules\@leafac\html\distribution\index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from C:\Users\Dell\AppData\Local\Temp\caxa\ktn\kerfwv1oby\node_modules\@leafac\html\package.json.

at Object.Module._extensions..js (internal/modules/cjs/loader.js:1089:13)
at Module.load (internal/modules/cjs/loader.js:937:32)
at Function.Module._load (internal/modules/cjs/loader.js:778:12)
at Module.require (internal/modules/cjs/loader.js:961:19)
at require (internal/modules/cjs/helpers.js:92:18)
at Object.<anonymous> (C:\Users\Dell\AppData\Local\Temp\caxa\ktn\kerfwv1oby\lib\index.js:13:16)
at Module._compile (internal/modules/cjs/loader.js:1072:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)
at Module.load (internal/modules/cjs/loader.js:937:32)
at Function.Module._load (internal/modules/cjs/loader.js:778:12) {

code: 'ERR_REQUIRE_ESM' }`

What can I do to solve it? I tried downgrading node-fetch as this post suggested but it didn't help.

leafac commented 2 years ago

Hi @ufo512,

Thanks for reaching out. It seems like you trying to build from the main branch, which may not be working on Windows. Can you please try to build from the latest release: https://github.com/leafac/kill-the-newsletter/tree/v1.0.1

Please let me know how it goes.

ufo512 commented 2 years ago

Thanks for your answer @leafac. I tried to build both from the main branch and v1.0.1 release, and I always got the same error.

leafac commented 2 years ago

Hmmm, thanks for trying. I’ll look into this and get back to you.

ufo512 commented 2 years ago

Thank you!

ufo512 commented 1 year ago

I rolled back the @leafac/html package to 3.0.0 and packaged it with pkg and the error disappeared. The problem is still not solved though, because when I package it with caxa, this error still pops up. Is it possiple to force caxa to use a particular version of a package?

leafac commented 1 year ago

@ufo512

caxa isn’t supposed to change the versions of packages. It’ll run npm dedupe --production, so just make sure you’re changing package versions in package.json, not just changing the contents of the node_modules/ folder.

But really, we need to figure out the underlying issue. I’ll get to it at some point, but please continue digging and report back on what you find 😁

ufo512 commented 1 year ago

I decided to go with pkg as I finally got it working and I'm not that familiar with node and TS to do that with caxa 😕

leafac commented 1 year ago

@ufo512 Oh, good to know that pkg works with Kill the Newsletter! 😀

I suppose we’re closing this issue for now. If you want to follow-up on something feel free to reopen it.