bjowes / cypress-ntlm-auth

Windows authentication plugin for Cypress
MIT License
54 stars 10 forks source link

'import' and 'export' may appear only with 'sourceType: module' When using suggested setting #194

Closed ghost closed 2 years ago

ghost commented 2 years ago

Hi, I started seeing the error today for the first time. Started totally new project, added cypress-ntlm-auth as a first plugin and when trying to run the test, got that "'import' and 'export' may appear only with 'sourceType: module'" ... It's due to Cypress now not liking the "import "cypress-ntlm-auth/dist/commands";" line in support/index.js ... image Commenting out line 18 gets rid of the error message - but then of course the step definitions fail ... Can you please update the readme - or the code so that the plugin could be imported in a different way?

bjowes commented 2 years ago

Thanks for reporting. A new version of this plugin was released yesterday so this is definitely connected to those changes. Please use the previous version (3.2.3) while I investigate.

ghost commented 2 years ago

Thank you for responding - that was fast! I think the problem is not in the plugin itself - rather in Cypress using babel 7.16.7, which seems not to like the "import ..." in the index.js file ... So anyone freshly installing cypress might get this ... I've also tried installing older version of Cypress, that didn't help. It gets the latest babel always :(

bjowes commented 2 years ago

I've tried to reproduce this but can't reach the error state you are seeing. Tested on OS X and Windows. Node 14 and 16. Cypress 9.4.1. What versions are you using?

However, there was another issue with the latest release related to SSL tunnels (https to non-NTLM sites), which I detected quickly as a side effect of you reporting this. A fix for that is in the works.

ghost commented 2 years ago

Thank you for your effort. I've got Windows 10 Pro, had Node 16 when I started seeing that message, removed that & went to Node 17. Had Cypress 9.4.1 before, now got 9.3.0. I've totally destroyed my environment - deleted all Cache from AppData folders, also for npm, before starting with the switch from Node 16 to 17. I've added also a cypress-cucumber-preprocessor - which is necessary for my project, that one is working - however unusable because now I fail on the first step - opening the homepage, for which I need the ntlm authentication ... So now I am blocked, just occasionally trying some other approach to the suggested "import "cypress-ntlm-auth/dist/commands";" in the index.js file - which always throws the above error when uncommented and getting a fail when I comment it out - just to see that I didn't break anything else and that the cucumber is still working ... Will try afresh today, however, I fear, I am going to run into the same issue.

bjowes commented 2 years ago

Ah, I could reproduce it now. After installing and configuring cypress-cucumber-preprocessor the issue appears. I need to investigate more. Could you confirm if switching to 3.2.3 worked for you? It worked for me.

ghost commented 2 years ago

Yes, confirmed. However I had to lower also the Node version for this version to work - and am not using the latest cypress-cucumber-preprocessor just to make sure that the babel version is lower ...

bjowes commented 2 years ago

Did you see this: https://github.com/TheBrainFamily/cypress-cucumber-preprocessor/issues/667

I am guessing it is related to the errors you are seeing.

ghost commented 2 years ago

Hmm, that looks like I should perhaps turn to the cypress-cucumber-preprocessor team ... I am so sorry for taking yout time!

bjowes commented 2 years ago

No worries. I will look into it a bit more myself, since I think combining cypress-ntlm-auth with cypress-cucumber-preprocessor is a fairly common usecase.

creage commented 2 years ago

@bjowes The ESM change breaks the API use too.

https://github.com/bjowes/cypress-ntlm-auth#cypress-ntlm-api becomes obsolete now...

bjowes commented 2 years ago

Not really @creage - If your own project is an ESM project you can still use the API. However, maybe the ecosystem is not ready for the move the ESM - I'll consider moving back to commonjs agan.

creage commented 2 years ago

You might want to release it as a major version bump, and not just as a minor/patch - such changes are quite significant, right? ;)

Our nightly tests failed on three envs due to this small update. Had to explicitly revert to 3.2.3.

bjowes commented 2 years ago

My apologies, and thanks for the feedback! Since most users don't use the API I think I overlooked how this change might impact them. It was published as a minor since there are no changes to APIs or commands, but as you pointed out the ESM change was indeed breaking for API users.

bjowes commented 2 years ago

I have reverted the move to ESM and gone back to CommonJS, released as 3.2.6. Tested with cypress-cucumber-preprocessor, works fine again.