badeball / cypress-cucumber-preprocessor

Run cucumber/gherkin-syntaxed specs with Cypress
MIT License
1.32k stars 149 forks source link

Build fails with new version #1011

Closed runenielsen closed 1 year ago

runenielsen commented 1 year ago

Current behavior

I get this error when building:

cypress.config.ts:4:33 - error TS2307: Cannot find module '@badeball/cypress-cucumber-preprocessor/esbuild' or its corresponding type declarations.

4 import createEsbuildPlugin from '@badeball/cypress-cucumber-preprocessor/esbuild';



Found 1 error in cypress.config.ts:4

### Desired behavior

No error.

### Test code to reproduce

It should be reproducible with the example, since it imports from the same package: https://github.com/badeball/cypress-cucumber-preprocessor/blob/master/docs/quick-start.md

### Versions

* **Cypress version**: 12.11.0
* **Preprocessor version**: 17.0.0
* **Node version**: 18.16.0

### Checklist

- [X] I've read the [FAQ](https://github.com/badeball/cypress-cucumber-preprocessor/blob/master/docs/faq.md).
- [X] I've read [instructions for logging issues](https://github.com/badeball/cypress-cucumber-preprocessor/blob/master/CONTRIBUTING.md#bug-reports).
- [X] I'm not using `cypress-cucumber-preprocessor@4.3.1` (package name has changed and it is no longer the most recent version, see [#689](https://github.com/badeball/cypress-cucumber-preprocessor/issues/689)).
badeball commented 1 year ago

From the contribution guidelines:

A good bug report shouldn't leave others needing to chase you up for more information.

I'm tempted to close the issue based on this alone, but I'll give you a chance.

I get this error when building:

What does this mean to you?

It should be reproducible with the example, since it imports from the same package: https://github.com/badeball/cypress-cucumber-preprocessor/blob/master/docs/quick-start.md

The examples are all tested in CI and run seemingly fine. You need to provide a runnable example without simply referring to documentation,

kogratte commented 1 year ago

Just installed the latest version. Got the exact same issue.

Screenshot 2023-05-02 at 14 28 00
badeball commented 1 year ago

@kogratte, set moduleResolution to node16 in your TS config.

kogratte commented 1 year ago

Works. Maybe should you update the doc accordingly?

kleinfreund commented 1 year ago

Setting moduleResolution to node16 doesn’t work for the application I’m working on as doing so causes some 200 new TypeScript errors across dozens of files in the project.

Among those errors are ones relating to CommonJS modules while treating the file as a true module, modules without type declarations (third party packages we don’t control), implicit anys, etc.

Is there any other way I can import createEsbuildPlugin on v17?

runenielsen commented 1 year ago

@badeball : Alright, sorry, I didn't notice this in the release notes. But that works, thank you.

I will close this. And thanks for the great tool.

badeball commented 1 year ago

@kleinfreund, you can EG. write module definitions yourself as a workaround,

// declarations.d.ts
declare module "@badeball/cypress-cucumber-preprocessor/esbuild";

or map the path

// tsconfig.json
{
  "compilerOptions": {
    "paths": {
      "@badeball/cypress-cucumber-preprocessor/esbuild": ["./node_modules/@badeball/cypress-cucumber-preprocessor/dist/bundler-utils/esbuild"]
    }
  }
}
badeball commented 1 year ago

@kleinfreund. this thread might give you more insight into what is going on with node16 resolution mode. Tldr is that many packages are wrongly configured. What packages are you having trouble with?

kleinfreund commented 1 year ago

@badeball Thanks for the quick help. I think manually mapping the path in the tsconfig.json is an adequate workaround to this.

Tldr is that many packages are wrongly configured. What packages are you having trouble with?

From what I can see, the packages vite and urlpattern-polyfill are producing errors of the following form:

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("urlpattern-polyfill")' call instead.
  To convert this file to an ECMAScript module, change its file extension to '.mts', or add the field `"type": "module"` to '/home/phil/kong/kuma-gui/package.json'.

And as for missing declaration files, I only see vuex and an internal package producing errors such as these:

Could not find a declaration file for module 'vuex'. '/home/phil/kong/kuma-gui/node_modules/vuex/dist/vuex.cjs.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/vuex` if it exists or add a new declaration (.d.ts) file containing `declare module 'vuex';`

Most if not all of these errors probably have easily explainable reasons completely out of the responsibilities/sphere of influence of this project of course.