简体   繁体   中英

How to fix “Cannot find module 'fs-extra' - error” When deploying cypress files into jenkins?

I am using plugins in cypress and referred to https://docs.cypress.io/api/plugins/configuration-api.html#Usage . When we deploy them into jenkins, I am getting

 `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'

I did go through a few threads which manually asks you to download the fs-extra in node_module. I did that and the dependency has been automatically added into the package.json file. However, the build fails. The code runs perfectly when you run locally and all the test passes. However, this fails when the deployed into jenkins.


// 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)

}

The code should deploy successfully on Jenkins, however, evening installing it locally on node_module doesn't work. Can somebody help in figuring out what I am missing, please?

This issue has been resolved. Thanks to @Mr.J. This had nothing to do with fs-extra. The entry point in docker file was not correct and I had to modify that. After modifying that, it worked fine.

If at all you have this issue, 1. Try installing fs-extra inside node_module. 2. please check the path in the cypress config file. 3. Check the path in docker file.

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