javascript - Cypress :找不到模块:错误:无法解析'cypress/types/lodash

标签 javascript node.js npm lodash cypress

我正在从 VS IDE 在 Cypress 中运行我的第一个测试,并且 Cypress 一直在工作,直到我遇到以下错误而没有更改或更新任何内容..
我的 Cypress (7.0.0)使用 Node.js 14.16.1 通过 NPM 命令安装,在执行我的测试时遇到“找不到模块:错误:无法解析 'cypress/types/lodash”错误消息。
我试图从项目中删除所有 loadash 文件并执行代码,但错误保持不变。
有人可以告诉我如何诊断或解决此问题!

错误消息:

Error: Webpack Compilation Error
./cypress/integration/myTests/helloWorld.test.js
Module not found: Error: Can't resolve 'cypress/types/lodash' in 'C:\Users\.....\Documents\.....\Tools\Cypress\Software\cypress\integration\myTests'
resolve 'cypress/types/lodash' in 'C:\Users\.....\Documents\.....\Tools\Cypress\Software\cypress\integration\myTests'
  Parsed request is a module
  using description file: C:\Users\.....\Documents\.....\Tools\Cypress\Software\package.json (relative path: ./cypress/integration/myTests)
    Field 'browser' doesn't contain a valid alias configuration
    Looked for and couldn't find the file at the following paths:
[C:\Users\.....\Documents\.....\Tools\Cypress\Software\cypress\integration\myTests\node_modules]
[C:\Users\.....\Documents\.....\Tools\Cypress\Software\cypress\integration\node_modules]
[C:\Users\.....\Documents\.....\Tools\Cypress\Software\cypress\node_modules]
[C:\Users\.....\Documents\.....\Tools\Cypress\node_modules]
[C:\Users\.....\Documents\.....\Tools\node_modules]
[C:\Users\.....\Documents\.....\node_modules]
[C:\Users\.....\Documents\node_modules]
[C:\Users\.....\node_modules]
[C:\Users\node_modules]
[C:\node_modules]
[C:\Users\.....\Documents\.....\Tools\Cypress\Software\node_modules\cypress\types\lodash]
[C:\Users\.....\Documents\.....\Tools\Cypress\Software\node_modules\cypress\types\lodash.js]
[C:\Users\.....\Documents\.....\Tools\Cypress\Software\node_modules\cypress\types\lodash.json]
[C:\Users\.....\Documents\.....\Tools\Cypress\Software\node_modules\cypress\types\lodash.jsx]
[C:\Users\.....\Documents\.....\Tools\Cypress\Software\node_modules\cypress\types\lodash.mjs]
[C:\Users\.....\Documents\.....\Tools\Cypress\Software\node_modules\cypress\types\lodash.coffee]
[C:\Users\.....\Documents\.....\Tools\Cypress\Software\node_modules\cypress\types\lodash\index]
[C:\Users\.....\Documents\.....\Tools\Cypress\Software\node_modules\cypress\types\lodash\index.js]
[C:\Users\.....\Documents\.....\Tools\Cypress\Software\node_modules\cypress\types\lodash\index.json]
[C:\Users\.....\Documents\.....\Tools\Cypress\Software\node_modules\cypress\types\lodash\index.jsx]
[C:\Users\.....\Documents\.....\Tools\Cypress\Software\node_modules\cypress\types\lodash\index.mjs]
[C:\Users\.....\Documents\.....\Tools\Cypress\Software\node_modules\cypress\types\lodash\index.coffee]
 @ ./cypress/integration/myTests/helloWorld.test.js 6:4-35
 
    at Watching.handle [as handler] (C:\Users\.....\AppData\Local\Cypress\Cache\7.0.0\Cypress\resources\app\packages\server\node_modules\@cypress\webpack-preprocessor\dist\index.js:172:23)
    at C:\Users\.....\AppData\Local\Cypress\Cache\7.0.0\Cypress\resources\app\packages\server\node_modules\webpack\lib\Watching.js:99:9
    at AsyncSeriesHook.eval [as callAsync] (eval at create (C:\Users\.....\AppData\Local\Cypress\Cache\7.0.0\Cypress\resources\app\packages\server\node_modules\tapable\lib\HookCodeFactory.js:33:10), <anonymous>:6:1)
    at AsyncSeriesHook.lazyCompileHook (C:\Users\.....\AppData\Local\Cypress\Cache\7.0.0\Cypress\resources\app\packages\server\node_modules\tapable\lib\Hook.js:154:20)
    at Watching._done (C:\Users\.....\AppData\Local\Cypress\Cache\7.0.0\Cypress\resources\app\packages\server\node_modules\webpack\lib\Watching.js:98:28)
    at C:\Users\.....\AppData\Local\Cypress\Cache\7.0.0\Cypress\resources\app\packages\server\node_modules\webpack\lib\Watching.js:73:19
    at Compiler.emitRecords (C:\Users\.....\AppData\Local\Cypress\Cache\7.0.0\Cypress\resources\app\packages\server\node_modules\webpack\lib\Compiler.js:499:39)
    at C:\Users\.....\AppData\Local\Cypress\Cache\7.0.0\Cypress\resources\app\packages\server\node_modules\webpack\lib\Watching.js:54:20
    at C:\Users\.....\AppData\Local\Cypress\Cache\7.0.0\Cypress\resources\app\packages\server\node_modules\webpack\lib\Compiler.js:485:14
    at AsyncSeriesHook.eval [as callAsync] (eval at create (C:\Users\.....\AppData\Local\Cypress\Cache\7.0.0\Cypress\resources\app\packages\server\node_modules\tapable\lib\HookCodeFactory.js:33:10), <anonymous>:6:1)
    at AsyncSeriesHook.lazyCompileHook (C:\Users\.....\AppData\Local\Cypress\Cache\7.0.0\Cypress\resources\app\packages\server\node_modules\tapable\lib\Hook.js:154:20)
    at C:\Users\.....\AppData\Local\Cypress\Cache\7.0.0\Cypress\resources\app\packages\server\node_modules\webpack\lib\Compiler.js:482:27
    at C:\Users\.....\AppData\Local\Cypress\Cache\7.0.0\Cypress\resources\app\packages\server\node_modules\neo-async\async.js:2818:7
    at done (C:\Users\.....\AppData\Local\Cypress\Cache\7.0.0\Cypress\resources\app\packages\server\node_modules\neo-async\async.js:3522:9)
    at AsyncSeriesHook.eval [as callAsync] (eval at create (C:\Users\.....\AppData\Local\Cypress\Cache\7.0.0\Cypress\resources\app\packages\server\node_modules\tapable\lib\HookCodeFactory.js:33:10), <anonymous>:6:1)
    at AsyncSeriesHook.lazyCompileHook (C:\Users\.....\AppData\Local\Cypress\Cache\7.0.0\Cypress\resources\app\packages\server\node_modules\tapable\lib\Hook.js:154:20)

最佳答案

请注意,在我的 js 文件中自动添加了以下内容;

const { contains } = require("cypress/types/jquery");

删除这行代码,问题解决

关于javascript - Cypress :找不到模块:错误:无法解析'cypress/types/lodash,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67019220/

相关文章:

javascript - jQuery - 这个语法是什么意思?

javascript - 将时间和数据存储在 firebase 数据库中

node.js - jspm 初始化返回 "jspm init has not yet been implemented"

angular - 尝试在 Angular 项目中导入 date-fns 时,Jest 测试失败

node.js - 如何验证node.js中navigator.id.get返回的断言?

javascript - 如何在谷歌搜索中制作菜单公司简介网站?如何编辑sitemap.xml 来设置它?

JavaScript 用于获取 URL 值并将其发布到 iFrames 中

javascript - 类型错误 : next is not a function

javascript - 为什么 node.js querysting 模块应该将加号 (+) 转换为空格?

javascript - 在 Javascript 中创建其他文件所需的模块?