webdriverio/webdriverio

Problem with Integration percy/webdriverio in project "Error: ReferenceError: require is not defined in ES module scope, you can use import instead"

Open

#14,192 创建于 2024年12月24日

在 GitHub 查看
 (13 评论) (0 反应) (0 负责人)JavaScript (6,029 star) (1,793 fork)batch import
Bug 🐛help wantedwdio-browserstack-service

描述

Environment (please complete the following information):

  • Node.js version: v 20.11.1
  • NPM version: 10.8.1
  • Platform: Android
  • Platform version: 13.0
  • Emulator/Simulator/Real Device: Emulator from Browserstack
  • TypeScript: 5.4.5

Describe the bug

  1. npm install --save-dev @percy/cli @percy/webdriverio
  2. Added require and await percySnapshot (see screen) in test
  3. Run test

Actual result: I get failed with error "Error: ReferenceError: require is not defined in ES module scope, you can use import instead". (check Logs when I use require.txt) Logs when I use require.txt My test with require

  1. Replaced const percySnapshot = require('@percy/webdriverio'); to import percySnapshot from '@percy/webdriverio';

Actual result: I get failed (check Logs when I use import.txt) Logs when I use import.txt

My test with import - error From Percy: 37950736_cli.json

FYI: I opened @percy/webdriverio and saw @percy/core The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("@percy/core")' call instead. Percy-Core

Additional context Settings: packagejson tsconfig

Could you give me advice how to fix my problem?

贡献者指南