【问题标题】:How to fix "Cannot find module 'fs-extra' - error" When deploying cypress files into jenkins?将柏树文件部署到詹金斯时如何解决“找不到模块'fs-extra' - 错误”?
【发布时间】:2019-05-20 02:45:14
【问题描述】:

我在 cypress 中使用插件并引用了 https://docs.cypress.io/api/plugins/configuration-api.html#Usage。当我们将它们部署到詹金斯时,我得到了

 `pluginsFile` is set to `/e2e/cypress/plugins/index.js`, but either the file is missing, it contains a syntax error, or threw an error when required. The `pluginsFile` must be a `.js` or `.coffee` file.

Please fix this, or set `pluginsFile` to `false` if a plugins file is not necessary for your project.[39m

Error: Cannot find module 'fs-extra'

我确实经历了一些手动要求您下载 node_module 中的 fs-extra 的线程。我这样做了,并且依赖项已自动添加到 package.json 文件中。但是,构建失败。当您在本地运行并且所有测试都通过时,代码可以完美运行。但是,当部署到詹金斯时,这会失败。


// promisified fs module
const fs = require('fs-extra')
const path = require('path')

function getConfigurationByFile (file) {
  const pathToConfigFile = path.resolve('cypress', 'config', `${file}.json`)

  return fs.readJson(pathToConfigFile)
}

module.exports = (on, config) => {
  // `on` is used to hook into various events Cypress emits
  // `config` is the resolved Cypress config
  // accept a configFile value or use development by default
 const file = config.env.configFile || 'environment-2'

 return getConfigurationByFile(file)

}

代码应该在 Jenkins 上成功部署,但是,晚上在 node_module 上本地安装它不起作用。有人可以帮我弄清楚我错过了什么吗?

【问题讨论】:

  • 甚至尝试将 fs-extra 从 dev 依赖项移动到依赖项,但仍然无法正常工作。
  • 看来 fs-extra 不是你的问题,但这是你的问题:pluginsFile` is set to `/e2e/cypress/plugins/index.js 你能验证/e2e/cypress/plugins/index.js 存在吗?我猜是 cypress 配置的 pluginsFile 不正确,指向了一个不存在的文件。
  • 你是对的。这与 fs-extra 无关。但是,我们从中部署到 Jenkins 的文件没有正确的入口点。所以不得不改变这一点。之后它工作得很好:)非常感谢

标签: javascript testing automated-tests cypress end-to-end


【解决方案1】:

此问题已解决。感谢@Mr.J。这与 fs-extra 无关。 docker 文件中的入口点不正确,我不得不修改它。修改后,它工作正常。

如果你有这个问题, 1. 尝试在 node_module 中安装 fs-extra。 2.请检查cypress配置文件中的路径。 3. 查看docker文件中的路径。

【讨论】:

  • 我遇到了这个问题,想知道它是如何解决的。我不太确定 docker 中的入口点。在我的 yaml 文件中,我有这样的内容:image: cypress/included:6.3.0(虽然我现在使用 bitbucket-pipelines,但在我之前的工作中,与 TeamCity 有同样的问题)。
猜你喜欢
  • 2019-12-21
  • 1970-01-01
  • 2013-04-08
  • 2021-08-31
  • 2015-03-02
  • 2019-09-10
  • 2020-12-29
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多