Node.js 错误找不到模块 [英] Node.js ERROR Cannot find Module

查看:53
本文介绍了Node.js 错误找不到模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我是 JS 和 Node.js 的新手,我在使用 Cucumber 和 PageObject 设置 webdriverio 项目时遇到了问题.每次我尝试运行测试时都会发生此错误:

Hey guys I'm new to JS and Node.js and I'm having trouble setting up a webdriverio project using cucumber and PageObject. And every time I try to run a test this error happens:

ERROR: Cannot find module '../support/action/openWebsite'
chrome
    at Function.Module._resolveFilename (module.js:469:15)
    at Function.Module._load (module.js:417:25)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/Users/axelbarford/Desktop/Oktana-training-webdriverio/src/steps/LoginStepDef/loginStepsDef.js:1:1)
    at Module._compile (module.js:570:32)
    at loader (/usr/local/lib/node_modules/babel-register/lib/node.js:144:5)
    at Object.require.extensions.(anonymous function) [as .js] (/usr/local/lib/node_modules/babel-register/lib/node.js:154:7)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)

这是调用 openWebSite 的 loginStepsDef.js 文件:

This is the loginStepsDef.js file where the openWebSite is being called:

 import openWebsite from '../support/action/openWebsite';
import LoginPage from '../pageobject/LoginPage/LoginPage';

module.exports = function given() {
    this.Given(
        /^I open salesforce login page$/,
            openWebsite
    );

    this.When(
        /^I set user "([^"]*)?" and password "([^"]*)?"$/, function(arg1,arg2) {
            LoginPage.open();
            LoginPage.username.setValue(arg1)
            LoginPage.password.setValue(arg2) 
        });

    this.And(
        /^I click the login button$/,function(){
            LoginPage.open();
            LoginPage.submit(); 
        });
}

知道会发生什么会很棒.你需要我展示更多的东西让我知道.

Any idea what could be happening would be great. Do you need me to show something more let me know.

推荐答案

试试这个:

 var openWebsite = require('../../support/action/openWebsite');
 var LoginPage = require('../../pageobject/LoginPage/LoginPage');

这篇关于Node.js 错误找不到模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆