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

Prevents booting when which is missing #108

Open
coder2000 opened this issue Jul 6, 2023 · 8 comments
Open

Prevents booting when which is missing #108

coder2000 opened this issue Jul 6, 2023 · 8 comments

Comments

@coder2000
Copy link

Current version apparently uses which to locate the mjml binary, however if it is not installed on the system the app will not boot and throw an exception.

@sighmon
Copy link
Owner

sighmon commented Jul 7, 2023

@coder2000 Does this config work for your use case? Which OS are you using?

# config/initializers/mjml.rb
Mjml.setup do |config|
  config.mjml_binary = "/path/to/custom/mjml"
end

@johannesschobel
Copy link

i think the issue is related to using yarn instead of npm.

I have the same issue - if i use yarn add mjml the binaries somehow are not found.
If i use npm install mjml, everything works as expected

@sighmon
Copy link
Owner

sighmon commented Jan 13, 2024

@johannesschobel Oh interesting. Is there something that can be done to fix it?

@johannesschobel
Copy link

Actually, I don't know yet.. I will try to set up a reproduction repository in order to isolate this issue. Will need some time for this. Maybe next week. I would like to rule other possible issues out, because I only tried this in my real application.

I will come back to this issue with more information and try to explain the steps.

All the best

@johannesschobel
Copy link

ok.. i think, i got one step closer..
in a "brand new repository(runrails new NAME, bundle add mjml-rails, yarn add mjml) and then start the application via rails s` works perfectly..

This left me puzzled, as i thought that this may be the issue..

Running yarn run mjml-cli --version also outputs the correct version numbers. so this should work.

Then i tried the same command yarn run mjml-cli --version in my production application (where this error occurs) - and this fails with the following error:

yarn run mjml-cli --version
yarn run v1.22.17
$ /home/schobel/projects/rails/XXX/node_modules/.bin/mjml-cli --version
/home/schobel/projects/rails/XXX/node_modules/string-width/index.js:2
const stripAnsi = require('strip-ansi');
                  ^

Error [ERR_REQUIRE_ESM]: require() of ES Module /home/schobel/projects/rails/XXX/node_modules/strip-ansi/index.js from /home/schobel/projects/rails/XXX/node_modules/string-width/index.js not supported.
Instead change the require of /home/schobel/projects/rails/XXX/node_modules/strip-ansi/index.js in /home/schobel/projects/rails/XXX/node_modules/string-width/index.js to a dynamic import() which is available in all CommonJS modules.
    at Object.<anonymous> (/home/schobel/projects/rails/XXX/node_modules/string-width/index.js:2:19)
    at Object.<anonymous> (/home/schobel/projects/rails/XXX/node_modules/cliui/build/index.cjs:291:21)
    at Object.<anonymous> (/home/schobel/projects/rails/XXX/node_modules/yargs/build/index.cjs:2861:12)
    at Object.<anonymous> (/home/schobel/projects/rails/XXX/node_modules/yargs/index.cjs:5:30)
    at Object.<anonymous> (/home/schobel/projects/rails/XXX/node_modules/mjml-cli/lib/client.js:34:37)
    at Object.<anonymous> (/home/schobel/projects/rails/XXX/node_modules/mjml-cli/bin/mjml:3:1) {
  code: 'ERR_REQUIRE_ESM'
}

Node.js v18.17.1
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

So the issue points to the require(...) statement in other javascript libraries.. damn, how i hate CJS / ESM conflicts.
I then manually changed the mentioned require(...) statements to import(...) statements (you only need to change "require" to "import" - thats all) and rerun yarn run mjml-cli --version and it now works.

Need to dig a bit deeper.. But these are my results so far.. Hope this helps someone a bit further. Will post updates again.

All the best,
Johannes

@johannesschobel
Copy link

if you then run npm install just once, it works.. i really don't know why..
you can then even remove the package-lock.json file.. and completely remove the node_modules folder.. and re-install via yarn and it works from now on..

dont ask?!

@johannesschobel
Copy link

In another github issue (cannot find the link) they mentioned, that this may be an issue related to an old version of yarn (1.x). I noticed, that if you update yarn via npm, it stays on the old version, as yarn itself is now "separated" from npm.

Note, that the default Dockerfile shipped with rails 7.1 relies on yarn 1.22.17 - which is quite old.

Issue could also be related to an old yarn version?!

I will try, if this is the case

@johannesschobel
Copy link

i ended up running a

npm install -g mjml

in my Dockerfile that creates the image for my server to get rid of the issue.
However, obviously, i am looking for a better solution ;)

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

3 participants