Cypress:找不到模块:错误:无法解析“cypress/types/lodash”

时间:2021-04-09 10:13:47

标签: javascript node.js npm lodash cypress

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

我使用 Node.js 14.16.1 通过 NPM 命令安装的 Cypress (7.0.0) 在执行我的测试时遇到“Module not found: Error: Can't resolve '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)

1 个答案:

答案 0 :(得分:1)

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

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

npm install

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

相关问题