moon-cli icon indicating copy to clipboard operation
moon-cli copied to clipboard

moon init err

Open moshuchao opened this issue 8 years ago • 20 comments

Error: ENOENT: no such file or directory, open '/usr/local/lib/node_modules/moon-cli/template/config.json'

moshuchao avatar Aug 29 '17 06:08 moshuchao

Huh, it seems to have not downloaded the template correctly. Can you check and see what the contents of /usr/local/lib/node_modules/moon-cli/template/ are?

kbrsh avatar Aug 29 '17 14:08 kbrsh

ls: /usr/local/lib/node_modules/moon-cli/template/: No such file or directory

moshuchao avatar Aug 30 '17 03:08 moshuchao

Odd, it looks like the template didn't download at all.

  1. Have you tried running it again?
  2. Make sure you are using the latest version of moon-cli.

kbrsh avatar Aug 30 '17 03:08 kbrsh

I have tried npm install moon-cli@latest -g again. Now, moon -v is 0.1.1, but run ls /usr/local/lib/node_modules/moon-cli/ , there is not template folder.

moshuchao avatar Aug 31 '17 10:08 moshuchao

That's odd. Moon reinstalls the latest moon-template whenever you run moon init. Have you tried that again?

Also, what platform are you on?

kbrsh avatar Aug 31 '17 14:08 kbrsh

I have too this problem. I am was trying on ubuntu, version of cli is 0.11.0

lexeech avatar Sep 05 '17 16:09 lexeech

A little late...but was also having this issue on Linux. Turns out was because the global install of moon-cli was with sudo, moon init also requires sudo to be able to save the latest template. There must be a better way to do this.

sudomabider avatar Sep 16 '17 03:09 sudomabider

Not sure why this issue was closed - could it be reopened?

I had the same problem on MacOS.

The cause is the template path using __dirname, which resolves to /usr/local/lib/node_modules/moon-cli/bin/moon. Then deleting from within that protected dir fails.

    // Download Template
    const templatePath = path.join(__dirname, "/../template");
    if(fs.existsSync(templatePath)) {
      del(templatePath);
    }

Could you use the cwd for the template dir? Since you're installing the template anew with each new project, does that template need to be installed in the global moon-cli dir rather than in the new project dir?

ElliotPsyIT avatar Sep 19 '17 17:09 ElliotPsyIT

@ElliotPsyIT I can reopen it, but I guess you're going to need the correct permissions to run it. The problem with downloading it into the new project, is that a new project will come with a template directory that is literally a clone of itself.

I guess I can change how this works though. Instead of caching it, I can just reinstall each time.

kbrsh avatar Sep 19 '17 22:09 kbrsh

So, if I understand the issue - moon-cli gets the source repo's template and replaces any existing one. This fails on MacOS if there is an existing template while deleting the old one, that is unless you use elevated permissions (sudo) when running the cli which permits the directory replacement.

My question is, do you need to actually write out a replacement template with each moon-cli run? Why not allow moon-cli to simply pull and use the repo's template with each run as it generates the new local project? This retains the repo template as the single source of truth for each cli run and avoids the write permission problems.

Apologies if I'm missing something ...

ElliotPsyIT avatar Sep 23 '17 16:09 ElliotPsyIT

In exploring, I see that I can simply remove this code in bin/moon to avoid deleting a protected directory. In doing so, moon init works on MacOS without elevated privileges (sudo):

if(fs.existsSync(templatePath)) {
  del(templatePath);
}

Wondering if you would you consider a pull request for this?

ElliotPsyIT avatar Sep 26 '17 20:09 ElliotPsyIT

@ElliotPsyIT The reason I cannot download the template directly to the new location is that it also uses a templating engine format.

Each file is a template that moon-cli compiles, which is why the title and descriptions are added to the packages as needed. The reason that it is deleted before it is downloaded is to ensure that you are getting the latest version of the template.

A PR would break this and you would be stuck with an outdated template. I think a fix would be to download the template to a new location.

Possibly ~/.moon-template?

kbrsh avatar Sep 26 '17 22:09 kbrsh

@kbrsh Ah, my apologies for not reading all through the download process to the compile step. I am a newbie, and obviously it shows. In any case, I like the idea of a dot file in the home dir for the template!

ElliotPsyIT avatar Sep 27 '17 13:09 ElliotPsyIT

i really like moon, hope this will be fixed soon 👍

lyquocnam avatar Nov 06 '17 17:11 lyquocnam

same here

JerryHuang2015 avatar Nov 10 '17 00:11 JerryHuang2015

Still having an issue with this. Seems the template downloads, but even if I create the file manually, config.json is removed upon running moon init <app-name>. Was anyone able to find a solution here? This was done with Moon CLI 0.1.1 and Moon version 0.11.0 as well as 1.0.0-beta.2.

funkybunch avatar Jan 13 '19 23:01 funkybunch

Moon requires Moon CLI version 1.0.0-beta.2 to be compatible with Moon 1.0.0-beta.2. For v1, the new syntax is:

$ moon <app-name>

For now, I think the fix is just running it with sudo because Moon may not have permission to download the template. Alternatively, you may be using incompatible versions or invalid syntax. Let me know if these work and if not, let me know what the error is.

kbrsh avatar Jan 14 '19 02:01 kbrsh

No dice with sudo. Seems the version of moon-cli downloaded when npm install moon-cli is run is still 0.1.1 (latest release). This still wants the syntax to be $ moon init <app-name> and I get the error Moon Err Command Not Found if I omit the init arg. Is there a new version of the CLI packaged in the 1.0.0 beta release of Moon? Else how do I download the new CLI version with the new init syntax?

funkybunch avatar Feb 09 '19 03:02 funkybunch

@funkybunch Try installing with:

$ npm install [email protected]

kbrsh avatar Feb 09 '19 03:02 kbrsh

@kbrsh got it working, thanks for the help!

funkybunch avatar Feb 09 '19 03:02 funkybunch