Skip to content
This repository has been archived by the owner on Jun 27, 2019. It is now read-only.

patternlab init throws an error #28

Closed
benhalverson opened this issue Feb 2, 2017 · 13 comments
Closed

patternlab init throws an error #28

benhalverson opened this issue Feb 2, 2017 · 13 comments
Assignees

Comments

@benhalverson
Copy link
Contributor

General information

patternlab init throws an error
OSX version 10.10.5

  • NodeJS version: 7.4.0
  • NPM version: 4.0.5

Problem description

After running patternlab init I get the following error:

    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
Copy link
Member

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
Copy link
Member

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

@benhalverson
Copy link
Contributor Author

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
Copy link
Contributor Author

@bmuenzenmeyer
Here are the workaround steps

  • npm init to create a package.json
  • npm i -s pattern-lab/patternlab-node-cli
  • patternlab init

@bmuenzenmeyer
Copy link
Member

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
Copy link
Contributor

@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 raphaelokon self-assigned this Feb 2, 2017
@raphaelokon
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Member

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
Copy link
Contributor

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.

bmuenzenmeyer added a commit to pattern-lab/patternlab-node that referenced this issue Feb 3, 2017
@raphaelokon
Copy link
Contributor

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

@leonardoalemax
Copy link

this should be in readme.md

@raphaelokon
Copy link
Contributor

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants