【问题标题】:Cannot find module '../built/cli.js' when running Protractor运行量角器时找不到模块'../built/cli.js'
【发布时间】:2016-07-04 02:32:13
【问题描述】:

由于present in Protractor 3.3.0 issue with getMultiCapabilities,我们必须直接从github安装Protractor,因为主分支包含the fix,它计划用于Protractor 3.4。

package.json 中,我们添加了以下内容:

"dependencies": {
  "protractor": "git+https://github.com/angular/protractor.git"
},

现在,我们在尝试运行 protractor 时遇到以下错误:

> protractor conf.js

module.js:341
    throw err;
    ^

Error: Cannot find module '../built/cli.js'

是我们做错了什么,还是Protractor开发版不能这样安装和使用?

【问题讨论】:

    标签: javascript node.js testing protractor


    【解决方案1】:

    npm 上下载包和在 git repo 上直接获取是不同的。

    防止量角器运行的要点是:

    //protractor from git repo, inside ./bin/protractor
    require('../built/cli.js');
    
    //protractor from npm, inside ./bin/protractor
    require('../lib/cli.js');
    

    所以基本上你需要去protractor本地文件夹然后执行gulp任务'prepublish'来设置protractor的环境。它会是这样的:

    // from your project directory
    cd node_modules/protractor
    // install base dependencies for protractor
    npm install
    // setup environment by publishing
    gulp prepublish
    

    【讨论】:

    • 应该是这样的——目前仍在确定在这种情况下使量角器命令工作的确切步骤。如果我找到修复它的命令序列,我会告诉你的。谢谢!
    • @alecxe 在回答我试图从 git repo 克隆量角器的问题之前。但是刚才我尝试通过npm命令安装它。使用npmgithub 获取包时,似乎重要的文件夹被遗漏了。您能否检查一下node_modules/protractor 中是否有以下文件夹:libscript...?因为在我的情况下,这些文件夹不是通过npm 安装的
    • 嗯,这又是一个奇怪的事情,从 github 安装时看起来非常精简,目录丢失。谢谢。
    【解决方案2】:

    据我所知,缺少一个步骤。 Protractor 在 package.json 中有 prepublish 步骤,你可以手动调用,或者尝试和这一步一样:

    Error: Cannot find module '../built/cli.js'
    

    我在https://github.com/angular/protractor/blob/master/gulpfile.js#L76看到的:

    gulp.task('prepublish', function(done) {
      runSequence(['typings', 'jshint', 'format'], 'tsc', 'tsc:globals', 'types',
        'ambient', 'built:copy', done);
    });
    
    gulp.task('built:copy', function() {
      return gulp.src(['lib/**/*','!lib/**/*.ts'])
          .pipe(gulp.dest('built/'));
    });
    

    我认为您只需要执行安装后任务,即可将该文件复制到目标位置。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-12-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-03
      相关资源
      最近更新 更多