Cypress-webpack-preprocessor出现Webpack编译错误

bttbmeg0  于 2022-12-19  发布在  Webpack
关注(0)|答案(1)|浏览(174)

我无法运行cypress测试并出现以下错误:
当我跑柏树赛跑时:
下面给出Webpack编译错误

Webpack Compilation Error
./cypress/integration/features/Pagination.feature
 Module not found: Error: Can't resolve 
'C:UsersCypressProjectode_modulescypress-cucumber-preprocessorlibesolveStepDefinition' in 'C:\Users\CypressProject\cypress\integration\features'

不知何故,反斜线也不包括在上述路径中

我的webpack配置文件是:

module.exports = {
resolve: {
  extensions: [".ts", ".js"]
},

node: { fs: "empty", child_process: "empty", readline: "empty" },
module: {
  rules: [
    {
      test: /\.ts$/,
      exclude: [/node_modules/],
      use: [
        {
          loader: "ts-loader"
        }
      ]
    },
    {
      test: /\.feature$/,
      use: [
        {
          loader: "cypress-cucumber-preprocessor/loader"
        }
      ]
    }
  ]
}
};

我的插件文件:

const wp = require('@cypress/webpack-preprocessor')

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) => {
    const file = process.env.ENV_FILE//config.env.envFile
  const options = {     
    webpackOptions: require("../webpack.config.js")
  };
  on('file:preprocessor', wp(options))
  if(file==null){
  return getConfigurationByFile('local');
  }
  else{
    return getConfigurationByFile(file);
  }
}

有人有解决的办法吗?

pkbketx9

pkbketx91#

您应该使用以下命令在package.json中设置step_definition路径

"cypress-cucumber-preprocessor": {
    "step_definitions": "path/to/steps_definition"
}

相关问题