Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type definitions export ES Modules but should export CommonJS #151

Closed
OliverJAsh opened this issue Jun 23, 2022 · 7 comments
Closed

Type definitions export ES Modules but should export CommonJS #151

OliverJAsh opened this issue Jun 23, 2022 · 7 comments
Assignees

Comments

@OliverJAsh
Copy link

OliverJAsh commented Jun 23, 2022

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

This is a brand new Cypress project.

Run yarn and then tsc.

tsc
cypress.config.js:7:13 - error TS2349: This expression is not callable.
  Type 'typeof import("/Users/oliverash/Development/temp/cypress-10-cypress-terminal-report-errors/node_modules/cypress-terminal-report/src/installLogsPrinter")' has no call signatures.

7             enableTerminalReportLogsPrinter(on);
              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


Found 1 error in cypress.config.js:7

This is happening because the type definitions are defined using ES Modules (export default installLogsPrinter;) however they should be defined as CommonJS (export = installLogsPrinter;) to match the JS source code.

export default installLogsPrinter;

module.exports = installLogsPrinter;

https://www.typescriptlang.org/docs/handbook/modules.html#export--and-import--require

Related change: 59f0ab9#diff-2a909c3c7c488c66f7e2c41d5b33f5c0f062d164a5a5e47485318e0697a0d7adL87

Related issue: #149

@archfz
Copy link
Owner

archfz commented Jun 23, 2022

Please check step 2 from install part of readme.

Based on that I think this duplicates #148

@OliverJAsh
Copy link
Author

@archfz
Copy link
Owner

archfz commented Jun 23, 2022

Can you please check the demo project from readme, using this plugin? That is also with typescript and it's working. Check for difference against your setup.

@OliverJAsh
Copy link
Author

OliverJAsh commented Jun 23, 2022

The difference is the Cypress config file in your demo uses ES imports: https://github.com/archfz/cypress-terminal-report-demo/blob/7d3c107bf102d0280b01431b3f518c5169561f73/cypress.config.ts#L2

Whereas the config file in my reduced test case is using a CommonJS require: https://github.com/OliverJAsh/cypress-10-cypress-terminal-report-errors/blob/67f6a73665790988aedd108494be1ee8b6b63022/cypress.config.js#L2

I think this tool should support config files with CommonJS as this is supported by Cypress. I have explained a way to fix this above.

@archfz
Copy link
Owner

archfz commented Jun 23, 2022

Ok thank you. PRs are welcome btw.

@archfz
Copy link
Owner

archfz commented Jul 4, 2022

Released fix in 4.0.2. Please test.

@archfz archfz closed this as completed Jul 4, 2022
@drebrez
Copy link
Contributor

drebrez commented Dec 9, 2022

Hi @archfz ,

I've just noticed that this problem also applies to the installLogsCollector.

In commit 743b551 you fixed it only for the installLogsPrinter.

I've created a PR with the fix #167

archfz added a commit that referenced this issue Dec 10, 2022
#151: Fix typescript declaration for support for both commonjs and esm.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants