【问题标题】:Cypress: Module not found: Error: Can't resolve 'cypress/types/lodash赛普拉斯:找不到模块:错误:无法解析 'cypress/types/lodash
【发布时间】:2021-07-05 05:20:30
【问题描述】:

我正在通过 VS IDE 在 Cypress 中运行我的第一个测试,并且 Cypress 一直在工作,直到我遇到以下错误而没有更改或更新任何内容..

使用 Node.js 14.16.1 通过 NPM 命令安装的赛普拉斯 (7.0.0) 在执行我的测试时遇到“找不到模块:错误:无法解析 '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)

【问题讨论】:

  • 请分享您的测试文件和 package.json 文件
  • 感谢@mosaad,我发现问题是我的测试文件中添加了一行新代码,不确定它是如何到达那里的,但删除它解决了问题。 "const { values } = require("cypress/types/lodash")"

标签: javascript node.js npm lodash cypress


【解决方案1】:

它表示在此路径上找不到您的文件 ./cypress/integration/myTests/helloWorld.test.js。检查文件是否真的存在于这个路径上,或者这个路径是否真的可以通过在 Visual Studio 代码中访问它来访问。

试试这个。在项目目录中输入命令行

npm install

然后再次运行,希望能解决问题

【讨论】:

  • 感谢 Abdullah !!!,似乎在我的测试文件中引入了一行新代码,导致测试失败。不确定如何将此行添加到代码中,但删除它对我有用! "const { values } = require("cypress/types/lodash")"
  • 这也发生在我身上。输入 .find 并导入 vscode import { find } from "cypress/types/lodash";
猜你喜欢
  • 2017-05-22
  • 2020-07-11
  • 2021-11-26
  • 2020-12-23
  • 1970-01-01
  • 2020-04-21
  • 1970-01-01
  • 2020-11-01
  • 1970-01-01
相关资源
最近更新 更多