Problem with Integration percy/webdriverio in project "Error: ReferenceError: require is not defined in ES module scope, you can use import instead"
#14,192 创建于 2024年12月24日
描述
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
- npm install --save-dev @percy/cli @percy/webdriverio
- Added require and await percySnapshot (see screen) in test
- 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
- 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
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.
Additional context
Settings:
Could you give me advice how to fix my problem?