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

MJML not found with NVM setup #83

Open
AlecRust opened this issue May 25, 2021 · 3 comments
Open

MJML not found with NVM setup #83

AlecRust opened this issue May 25, 2021 · 3 comments

Comments

@AlecRust
Copy link

AlecRust commented May 25, 2021

Background

After a format of my machine and careful new setup via my dotfiles, I have Node installed only via NVM (no duplicate Homebrew Node version at /usr/local/node) and have installed global Node packages using npm with the recommended approach. This includes Yarn, which they recommend installing via npm.

Point being I'm fairly confident I have a "clean" Node setup with no duplicates, everything installed as-per docs and scoped to the chosen NVM Node version.

Problem

I have mjml in my project's package.json and have ran yarn.

"mjml": "^4.9.3",

But I get this error from mjml-rails:

Couldn't find the MJML 4. binary.. have you run $ npm install mjml?

Even if make MJML a global package with npm install -g mjml I get the same error.

I'm not sure if local project npm install mjml works, but we use Yarn instead. Does mjml-rails rely on local project npm usage instead of Yarn?

@AlecRust AlecRust changed the title MJML must be installed globally MJML not found with NVM setup May 25, 2021
@sighmon
Copy link
Owner

sighmon commented May 26, 2021

@AlecRust I don't use yarn, so I've never tested mjml-rails functionality with it.

But other contributors have added yarn support, here's where it's checked: https://github.com/sighmon/mjml-rails/blob/master/lib/mjml.rb#L67

Looking at the way we look for a valid yarn mjml binary, can you see anywhere where it might be failing for your setup?

  def self.check_for_yarn_mjml_binary
    yarn_bin = `which yarn`.chomp
    return unless yarn_bin.present?
    mjml_bin = "#{yarn_bin} run mjml"
    return mjml_bin if check_version(mjml_bin)
  end

@AlecRust
Copy link
Author

Thanks @sighmon. I see that code runs which yarn to find the binary. I assume this is the issue, as which yarn in my case doesn't return a path to a binary, but a function:

yarn () {
    unset -f changelog emoj eslint gulp lungo ncu node nodemon npm npm-check npm-check-updates npx retry serve splash stylelint yarn yarnpkg yo yo-complete nvm > /dev/null 2>&1
    _zsh_nvm_load
    yarn "$@"
}

This is standard based on the NVM/npm installed Yarn setup described above, however sometimes when I run which yarn I do get a binary path:

/Users/alec/.nvm/versions/node/v16.2.0/bin/yarn

Looks like the check code would work for a Homebrew or manual Yarn installation which adds /usr/local/bin/yarn, but not with the recommended approach of installing yarn with npm install --global yarn, when using NVM.

@AlecRust
Copy link
Author

OK, figured out what is causing this. I had export NVM_LAZY_LOAD=true in my ~/.zshrc which is an option of zsh-nvm.

I have disabled this, but I don't seem to have this issue with other gems or Node packages. A very crude solution would be to include this command in your gem before the code that runs which yarn:

source "$NVM_DIR/nvm.sh"

AlecRust added a commit to AlecRust/dotfiles that referenced this issue May 28, 2021
Causes `which yarn` within mjml-rails gem to return a function instead of path.

sighmon/mjml-rails#83
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

2 participants