【问题标题】:Webpack compilation error with Cypress-webpack-preprocessor使用 Cypress-webpack-preprocessor 的 Webpack 编译错误
【发布时间】:2020-10-31 03:37:16
【问题描述】:

我无法运行 cypress 测试并出现以下错误:

当我运行 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);
  }
}

有人想解决吗?

【问题讨论】:

    标签: npm webpack cypress


    【解决方案1】:

    您应该在package.json 中设置step_definition 路径

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

    【讨论】:

    • 我仍然遇到类似 ./cypress/support/step_definitions/steps.ts 的问题 模块构建失败(来自 ./node_modules/cypress/index.js):LoaderRunnerError: Module 'C:\Users\ ui\node_modules\cypress\index.js' 不是加载器(必须有 normal 或 pitch 功能)@ ./cypress/integration/features/TC_170.feature 37:0-157 @multi ./cypress/integration/features/TC_170 .feature
    猜你喜欢
    • 2023-01-05
    • 2017-08-21
    • 2016-10-20
    • 2018-08-23
    • 2016-07-01
    • 1970-01-01
    • 2016-12-08
    • 1970-01-01
    • 2021-06-09
    相关资源
    最近更新 更多