pattern-lab / patternlab-node-cli

Moved to https://github.com/pattern-lab/patternlab-node/tree/dev/packages/cli
MIT License
21 stars 5 forks source link

patternlab init throws an error #28

Closed benhalverson closed 7 years ago

benhalverson commented 7 years ago

General information

patternlab init throws an error OSX version 10.10.5


    if (err) { throw err; }
               ^

Error: ENOENT: no such file or directory, scandir '/Users/benhalverson/projects/pl-test/node_modules'
    at Object.fs.readdirSync (fs.js:871:18)
    at diveSync (/Users/benhalverson/.nvm/versions/node/v7.4.0/lib/node_modules/patternlab-node-cli/node_modules/diveSync/diveSync.js:30:19)
    at findEngineModulesInDirectory (/Users/benhalverson/.nvm/versions/node/v7.4.0/lib/node_modules/patternlab-node-cli/node_modules/patternlab-node/core/lib/pattern_engines.js:37:3)
    at /Users/benhalverson/.nvm/versions/node/v7.4.0/lib/node_modules/patternlab-node-cli/node_modules/patternlab-node/core/lib/pattern_engines.js:58:28
    at Array.forEach (native)
    at loadAllEngines (/Users/benhalverson/.nvm/versions/node/v7.4.0/lib/node_modules/patternlab-node-cli/node_modules/patternlab-node/core/lib/pattern_engines.js:57:22)
    at Object.<anonymous> (/Users/benhalverson/.nvm/versions/node/v7.4.0/lib/node_modules/patternlab-node-cli/node_modules/patternlab-node/core/lib/pattern_engines.js:183:1)
    at Module._compile (module.js:571:32)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)```

### Reproduction steps
npm i -g pattern-lab/patternlab-node-cli
patternlab init 
bmuenzenmeyer commented 7 years ago

First up, thanks for helping us test the CLI. It's important for more 👀 to get on it.

I did some testing too.

I cannot even run patternlab -h in a new directory. I would expect that to be able to output the help at least.

If I cd to a directory that has an edition setup within it, patternlab -h does work. So it seems to me that in both cases of failure, the CLI is expecting some structure to exist... but how much?

...

more testing

...

okay, so I added a node_modules/ directory in the folder I was testing within and now patternlab -h works. Can we add that if not found?

bmuenzenmeyer commented 7 years ago

and @benhalverson can you try adding node_modules/ and then run init again?

benhalverson commented 7 years ago

Heres the new error for patterlab init



Loading engines from the edition or test directory...

/Users/benhalverson/.nvm/versions/node/v7.4.0/lib/node_modules/patternlab-node-cli/node_modules/patternlab-node/core/lib/pattern_engines.js:85
    throw new Error('No engines loaded! Something is seriously wrong.');
    ^

Error: No engines loaded! Something is seriously wrong.
    at loadAllEngines (/Users/benhalverson/.nvm/versions/node/v7.4.0/lib/node_modules/patternlab-node-cli/node_modules/patternlab-node/core/lib/pattern_engines.js:85:11)
    at Object.<anonymous> (/Users/benhalverson/.nvm/versions/node/v7.4.0/lib/node_modules/patternlab-node-cli/node_modules/patternlab-node/core/lib/pattern_engines.js:183:1)
    at Module._compile (module.js:571:32)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Module.require (module.js:498:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/Users/benhalverson/.nvm/versions/node/v7.4.0/lib/node_modules/patternlab-node-cli/node_modules/patternlab-node/core/lib/object_factory.js:3:22)```
benhalverson commented 7 years ago

@bmuenzenmeyer Here are the workaround steps

bmuenzenmeyer commented 7 years ago

A ha! thanks for the additional troubleshooting.

npm i -s pattern-lab/patternlab-node-cli

Interesting that you have to install the cli locally in order for it to work. My theory with the previous stack trace was that pattern_engines was failing because it could not find the default mustache pattern engine, which was installed along with the cli and core library in your global locations, rather than the current working directory

raphaelokon commented 7 years ago

@benhalverson @bmuenzenmeyer Thanks for the report.Can we create a minimal test case for this.

From what I read is that you install the cli globally and then try to run patternlab init it in a project dir, correct?

raphaelokon commented 7 years ago

Okay, I was able to reproduce the error:

  1. Install cli globally
  2. Create a folder an run patternlab --help
  3. Results in the same engine error from above

This is a bug.

raphaelokon commented 7 years ago

Okay, so far what I get from looking into the issues around global cli is that the core's postinstall isn't run for me after installing the cli.

When I try to manually run the core's postinstall from the global cli I get:

→ patternlab-node: node core/scripts/postinstall.js 
Beginning Pattern Lab postinstall...
No starterkits found to automatically load.

@bmuenzenmeyer any ideas?

bmuenzenmeyer commented 7 years ago

No engines loaded! Something is seriously wrong

it's failing because pattern_engines is not looking for potentially globally installed engines. We need to research how to look for globally installed packages. Or does require() just degrade to that?

....

doing some quick research, it seems that expecting modules to be installed globally is not a good idea, and it's best to put your dependencies into the local node_modules/ whenever possible.

Does this fundamentally change the CLI then, or am I misreading something?

raphaelokon commented 7 years ago

doing some quick research, it seems that expecting modules to be installed globally is not a good idea, and it's best to put your dependencies into the local node_modules/ whenever possible.

What do you refer to by dependencies?

Does this fundamentally change the CLI then, or am I misreading something?

I do not think so :-) CLI is should be pretty agnostic for such things.

it's failing because pattern_engines is not looking for potentially globally installed engines. We need to research how to look for globally installed packages. Or does require() just degrade to that?

AFAIK require resolves only to your package's local node_modules which is good. Except you pointing NODE_PATH to your global node_modules.

raphaelokon commented 7 years ago

Closing as this is a won't fix for global installs until we hit #32

leonardoalemax commented 6 years ago

this should be in readme.md

raphaelokon commented 6 years ago

@leualemax You are right. Thanks for pointing it out.