简体   繁体   中英

(generator-polymer) yo polymer fails, cannot find module 'find-index'

Here is the full error after typing yo polymer in a clean directory.

module.js:338
    throw err;
          ^
Error: Cannot find module 'find-index'
    at Function.Module._resolveFilename (module.js:336:15)
    at Function.Module._load (module.js:278:25)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)
    at Object.<anonymous> (/usr/lib/node_modules/generator-polymer/node_modules/yeoman-generator/node_modules/download/node_modules/vinyl-fs/node_modules/glob-stream/node_modules/glob2base/index.js:4:17)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Module.require (module.js:365:17)

I've just done a reinstall of everything node related, but here are the versions.

node:              v0.12.7
npm:               2.11.3
yo:                1.4.7
bower:             1.4.1
grunt-cli:         v0.1.13
gulp:              3.9.0
generator-polymer: 1.0.5

Note that I get a warning when installing generator-polymer .

npm WARN deprecated CSSselect@0.4.1: the module is now available as 'css-select'
npm WARN deprecated CSSwhat@0.4.7: the module is now available as 'css-what'

I have also tried installing the three problematic modules manually, which appeared to be successful.

sudo npm install -g find-index css-select css-what

I'm out of ideas. Node was installed from source downloaded at nodejs.org.

EDIT: I have also installed n using sudo npm install -gn to install node. I have tried uninstalling/reinstalling node/npm with no luck.

EDIT2: yo webapp works, so the culprit is (must be?) generator-polymer.

I see you are installing it to global modules. Did you try to install generator-polymer just for project (it should fix warnings)

You list only root packages version. But problem seems to be in dependencies. Accordign your stack trace it's caused by yeoman-generator / download module

Here is my versions of all depes. Look at this packages and check your version (i have yeoman-generator@0.18.10 and download@3.3.0 which works fine)

generator-polymer@1.1.0 node_modules/generator-polymer
├── ncp@2.0.0
├── chalk@1.1.0 (escape-string-regexp@1.0.3, supports-color@2.0.0, ansi-styles@2.1.0, has-ansi@2.0.0, strip-ansi@3.0.0)
├── lodash@3.10.1
├── validate-element-name@1.0.0 (log-symbols@1.0.2, ncname@1.0.0)
├── rimraf@2.4.2 (glob@5.0.14)
├── yosay@1.0.5 (ansi-regex@1.1.1, ansi-styles@2.1.0, strip-ansi@2.0.1, word-wrap@1.1.0, pad-component@0.0.1, minimist@1.1.3, taketalk@1.0.0, repeating@1.1.3, string-width@1.0.1)
└── yeoman-generator@0.18.10 (read-chunk@1.0.1, dargs@3.0.1, detect-conflict@1.0.0, yeoman-welcome@1.0.1, xdg-basedir@1.0.1, user-home@1.1.1, class-extend@0.1.1, diff@1.4.0, text-table@0.2.0, mime@1.3.4, underscore.string@2.4.0, async@0.9.2, run-async@0.1.0, istextorbinary@1.0.2, debug@2.2.0, nopt@3.0.3, cross-spawn@0.2.9, yeoman-assert@1.0.0, mkdirp@0.5.1, shelljs@0.3.0, cli-table@0.3.1, pretty-bytes@1.0.4, through2@0.6.5, glob@4.5.3, findup-sync@0.2.1, file-utils@0.2.2, dateformat@1.0.11, github-username@1.1.1, lodash@2.4.2, gruntfile-editor@0.2.0, download@3.3.0, mem-fs-editor@1.2.3, sinon@1.15.4, inquirer@0.8.5, yeoman-environment@1.2.7, cheerio@0.18.0)

Anyway, I would try install all deps as local modules.

EDIT: you should have this directory in you project

node_modules/generator-polymer/node_modules/yeoman-generator/node_modules/download/node_modules/vinyl-fs/node_modules/glob-stream/node_modules/glob2base/node_modules/find-index

where in tree glob2base is 0.0.12 glob-stram is 3.1.18 vinyl-fs is 0.3.13 download is 3.3.0 yeoman-generator is 0.18.10

There is a problem with using npm -g unless you can access it without using sudo (ie you have permission to read/write etc in the place where the global modules are installed).

As far as I can work out its bower that is the culprit

The way round the problem is to run npm config edit, and change the prefix value to something you do have access to without sudo. This edits ~/.npmrc file

You then install globally for you.

I was able to fix the issue by deleting the offending directory,

/usr/lib/node_modules/generator-polymer

I do not remember if simply reinstalling generator polymer ( sudo npm install -g generator-polymer ) fixed the issue completely (let me know and i'll update the answer). I ended up reinstalling everything to make sure any issues were mitigated.

Environment setup

  1. Install node.js . Follow the instructions on their site to install for your OS.
  2. Install Yeoman by typing the command sudo npm install -g yo in your system's console. The -g installs the package globally, which is why the sudo command is needed (your system may vary).
  3. Next we'll install a couple of Yeoman generators .
    1. Install the polymer generator with the command sudo npm install -g generator-polymer .
    2. (optional) Install the polymer element generator with the command sudo npm install -g generator-element . This will help with scaffolding out custom Polymer elements.

Starting a new project

With the development environment setup, starting a project is extremely easy.

mkdir my-project
cd my-project
yo polymer

A new polymer project will be setup in the my-project directory using the latest releases of polymer and other dependencies.

Testing a project

Polymer uses the gulp streaming build system. From your project's directory, simply type

gulp serve

See my Polymer 1.0 Notes Google doc.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM