question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

@cypress/webpack-preprocessor: missing type dependencies and other type errors

See original GitHub issue

Current behavior

Reduced test case: https://github.com/OliverJAsh/cypress-10-ts-errors

This is a brand new Cypress project using the latest version of all libraries.

Run yarn and then tsc.

Result:

$ tsc
node_modules/@cypress/webpack-preprocessor/dist/index.d.ts:1:23 - error TS2688: Cannot find type definition file for 'webpack-dev-server'.

1 /// <reference types="webpack-dev-server" />
                        ~~~~~~~~~~~~~~~~~~

node_modules/@cypress/webpack-preprocessor/dist/index.d.ts:2:23 - error TS2688: Cannot find type definition file for 'webpack-dev-server-3'.

2 /// <reference types="webpack-dev-server-3" />
                        ~~~~~~~~~~~~~~~~~~~~

node_modules/@cypress/webpack-preprocessor/dist/index.d.ts:4:26 - error TS7016: Could not find a declaration file for module 'bluebird'. '/Users/oliverash/Development/temp/cypress-10-ts-errors/node_modules/bluebird/js/release/bluebird.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/bluebird` if it exists or add a new declaration (.d.ts) file containing `declare module 'bluebird';`

4 import * as Promise from 'bluebird';
                           ~~~~~~~~~~


Found 3 errors in the same file, starting at: node_modules/@cypress/webpack-preprocessor/dist/index.d.ts:1

I attempted to workaround these errors by installing some of the missing type dependencies: https://github.com/OliverJAsh/cypress-10-ts-errors/commit/0e602ffe9a4d89372e68c06e849d12fa32af23ff

However, now I have a different error:

$ tsc
cypress.config.ts:7:16 - error TS2769: No overload matches this call.
  The last overload gave the following error.
    Argument of type '"file:preprocessor"' is not assignable to parameter of type '"task"'.

7             on("file:preprocessor", webpackPreprocessor({}));
                 ~~~~~~~~~~~~~~~~~~~

  node_modules/cypress/types/cypress.d.ts:5521:5
    5521     (action: 'task', tasks: Tasks): void
             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    The last overload is declared here.

node_modules/@cypress/webpack-preprocessor/dist/index.d.ts:2:23 - error TS2688: Cannot find type definition file for 'webpack-dev-server-3'.

2 /// <reference types="webpack-dev-server-3" />
                        ~~~~~~~~~~~~~~~~~~~~


Found 2 errors in 2 files.

Errors  Files
     1  cypress.config.ts:7
     1  node_modules/@cypress/webpack-preprocessor/dist/index.d.ts:2

Desired behavior

No type errors.

Test code to reproduce

See above.

Cypress Version

10.2.0

Other

Related: https://github.com/cypress-io/cypress/issues/9570

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:9 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
OliverJAshcommented, Aug 5, 2022

Also, if we don’t type check this file and we only rely on type checking inside our editors, the next time someone opens it in their editor they might be surprised to find a type error left by someone else. We type check all files in our CI build to ensure that all files remain free of type errors so there are no nasty surprises like this.

1reaction
lmiller1990commented, Jun 27, 2022

Can you send me your test case so I can see how it compares to mine?

I copied pasted the tsconfig.json from here into cypress then ran yarn tsc --project cyperss. I just realized it was not compiling cypress.config.ts, though - so actually, it’s not type checking cypress.config.ts. 👎, so disregard my initial comment.

I wonder if webpack-preprocessor even needs the webpack-dev-server (and webpack-dev-server-3 types) at all. It doesn’t list those dependencies anywhere, so I think this is probably a bug in how we generate our types. Either way, this seems like a bug to me.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Webpack Compilation Error with Cypress 10 and Cucumber in ...
You're just missing the webpack process, from quick-start. Then configure your preferred bundler to process features files.
Read more >
@cypress/webpack-preprocessor - npm
Start using @cypress/webpack-preprocessor in your project by running ... TypeScript icon, indicating that this package has built-in type ...
Read more >
cypress-io/cypress - Gitter
This is usually caused by: - A missing file or dependency - A syntax error in the file or one of its dependencies...
Read more >
Code Coverage - Cypress Documentation
As you write more and more end-to-end tests, you will find yourself wondering ... the application code and not 3rd party dependencies from...
Read more >
unmet peer dependencies pnpm - You.com | The AI Search ...
Apparently if a nested module fails to install during npm install, subsequent npm install won't detect those missing nested dependencies. If that's the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found