(发生器 – 聚合物)聚合物失效,找不到模块'find-index'

在干净的目录中inputyo polymer后,这是完整的错误。

 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) 

我刚刚重新安装了所有相关的节点,但这里是版本。

 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 

请注意,安装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' 

我也尝试手动安装三个有问题的模块,这似乎是成功的。

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

我没有想法。 节点是从nodejs.org下载的源代码安装的。

编辑:我也安装n使用sudo npm install -gn来安装节点。 我试图卸载/重新安装节点/ NPM没有运气。

编辑2: yo webapp工作,所以罪魁祸首是(必须是?)发生器聚合物。

我看到你正在将其安装到全局模块。 你是否尝试安装generator-polymer只是项目(它应该修复警告)

您只列出根包版本。 但问题似乎在依赖。 根据yeoman-generator / download模块调整堆栈跟踪

这是我所有的版本。 看看这个软件包,并检查您的版本(我有yeoman-generator@0.18.10和download@3.3.0这工作正常)

 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) 

无论如何,我会尝试安装所有代表本地模块。

编辑:你应该在你的项目中有这个目录

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

其中在glob2中的glob2base是0.0.12 glob-stram是3.1.18 vinyl-fs是0.3.13下载是3.3.0 yeoman-generator是0.18.10

使用npm -g存在一个问题,除非你可以在不使用sudo的情况下访问它(也就是说,你有权限在安装全局模块的地方读/写等)。

至于我可以找出它的罪魁祸首

解决问题的方法是运行npm config edit,并将前缀值更改为您有权访问的内容,而不使用sudo。 这编辑〜/ .npmrc文件

然后,您为您安装全球。

我能够通过删除违规目录来解决问题,

/usr/lib/node_modules/generator-polymer

我不记得是否简单地重新安装发电机聚合物( sudo npm install -g generator-polymer )完全解决了这个问题(让我知道,我会更新答案)。 我最终重新安装了一切,以确保任何问题得到缓解。

环境设置

  1. 安装node.js。 按照其网站上的说明为您的操作系统安装。
  2. 通过在系统控制台input命令sudo npm install -g yo来安装Yeoman 。 -g全局安装软件包,这就是为什么需要sudo命令(您的系统可能会有所不同)。
  3. 接下来,我们将安装几个Yeoman发电机 。
    1. 用命令sudo npm install -g generator-polymer
    2. (可选)使用命令sudo npm install -g generator-element安装聚合物元素生成 sudo npm install -g generator-element 。 这将有助于脚手架定制聚合物元素。

开始一个新项目

通过开发环境设置,启动项目非常简单。

 mkdir my-project cd my-project yo polymer 

一个新的聚合物项目将使用最新版本的聚合物和其他依赖项在my-project目录中设置。

testing一个项目

聚合物使用吞吐stream构build系统。 从您的项目目录中,只需键入

 gulp serve 

请参阅我的Polymer 1.0 Notes Google文档。