bjowes / cypress-ntlm-auth

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

"Error: Webpack Compilation Error" On fresh cypress setup #159

Closed davidhel closed 3 years ago

davidhel commented 3 years ago

Hi, I am new to this library and cypress. I successfully configured cypress with Angular using this tool: @briebug/cypress-schematic So I use Cypress with TypeScript.

However when setting up this library I am not getting past this issue:

Error: Webpack Compilation Error
C:/Users/MyUser/AppData/Roaming/npm/node_modules/cypress-ntlm-auth/node_modules/node-gyp-build/index.js
Module not found: Error: Can't resolve 'fs' in 'C:\Users\MyUser\AppData\Roaming\npm\node_modules\cypress-ntlm-auth\node_modules\node-gyp-build'
resolve 'fs' in 'C:\Users\MyUser\AppData\Roaming\npm\node_modules\cypress-ntlm-auth\node_modules\node-gyp-build'
  Parsed request is a module
  using description file: C:\Users\MyUser\AppData\Roaming\npm\node_modules\cypress-ntlm-auth\node_modules\node-gyp-build\package.json (relative path: .)
    Field 'browser' doesn't contain a valid alias configuration
    Looked for and couldn't find the file at the following paths:
[C:\Users\MyUser\AppData\Roaming\npm\node_modules\cypress-ntlm-auth\node_modules\node-gyp-build\node_modules]
[C:\Users\MyUser\AppData\Roaming\npm\node_modules\cypress-ntlm-auth\node_modules\node_modules]
[C:\Users\MyUser\AppData\Roaming\npm\node_modules\node_modules]
[C:\Users\MyUser\AppData\Roaming\node_modules]
[C:\Users\MyUser\AppData\node_modules]
[C:\Users\MyUser\node_modules]
[C:\Users\node_modules]
[C:\node_modules]
[C:\Users\MyUser\AppData\Roaming\npm\node_modules\cypress-ntlm-auth\node_modules\fs]
[C:\Users\MyUser\AppData\Roaming\npm\node_modules\package.json]
[C:\Users\MyUser\AppData\Roaming\npm\node_modules\cypress-ntlm-auth\node_modules\fs.ts]
[C:\Users\MyUser\AppData\Roaming\npm\node_modules\fs]
[C:\Users\MyUser\AppData\Roaming\npm\node_modules\cypress-ntlm-auth\node_modules\fs.js]
[C:\Users\MyUser\AppData\Roaming\npm\node_modules\fs.ts]
[C:\Users\MyUser\AppData\Roaming\npm\node_modules\fs.js]
[C:\Users\MyUser\AppData\Roaming\npm\node_modules\fs\index.js]
[C:\Users\MyUser\AppData\Roaming\npm\node_modules\fs\index.js.ts]
[C:\Users\MyUser\AppData\Roaming\npm\node_modules\fs\index.js.js]
[C:\Users\MyUser\AppData\Roaming\npm\node_modules\fs\index]
[C:\Users\MyUser\AppData\Roaming\npm\node_modules\fs\index.ts]
 @ C:/Users/MyUser/AppData/Roaming/npm/node_modules/cypress-ntlm-auth/node_modules/node-gyp-build/index.js 1:9-22
 @ C:/Users/MyUser/AppData/Roaming/npm/node_modules/cypress-ntlm-auth/node_modules/win-sso/dist/win-sso.js
 @ C:/Users/MyUser/AppData/Roaming/npm/node_modules/cypress-ntlm-auth/node_modules/win-sso/dist/index.js
 @ C:/Users/MyUser/AppData/Roaming/npm/node_modules/cypress-ntlm-auth/dist/util/sso.config.validator.js
 @ C:/Users/MyUser/AppData/Roaming/npm/node_modules/cypress-ntlm-auth/dist/commands/index.js
 @ ./cypress/support/index.ts

This error shows inside cypress browser after starting a spec file test.

I have tried both these two setups: https://github.com/bjowes/cypress-ntlm-auth/blob/master/README.md#docker-and-global-installs

In my support/index.ts file I have added: import 'C:/Users/MyUser/AppData/Roaming/npm/node_modules/cypress-ntlm-auth/dist/commands';

If I remove that line, it works as normal before adding this library. If I add this line: import 'cypress-ntlm-auth/dist/commands'; I get this error:

Error: Webpack Compilation Error
./node_modules/node-gyp-build/index.js
Module not found: Error: Can't resolve 'fs' in 'C:\Users\MyUser\Source\Repos\MyProject\node_modules\node-gyp-build'
resolve 'fs' in 'C:\Users\MyUser\Source\Repos\MyProject\node_modules\node-gyp-build'
  Parsed request is a module
  using description file: C:\Users\MyUser\Source\Repos\MyProject\node_modules\node-gyp-build\package.json (relative path: .)
    Field 'browser' doesn't contain a valid alias configuration
    Looked for and couldn't find the file at the following paths:
[C:\Users\MyUser\Source\Repos\MyProject\node_modules\node-gyp-build\node_modules]
[C:\Users\MyUser\Source\Repos\MyProject\node_modules\node_modules]
[C:\Users\MyUser\Source\Repos\MyProject\node_modules]
[C:\Users\MyUser\Source\Repos\node_modules]
[C:\Users\MyUser\Source\node_modules]
[C:\Users\MyUser\node_modules]
[C:\Users\node_modules]
[C:\node_modules]
[C:\Users\MyUser\Source\Repos\MyProject\node_modules\fs]
[C:\Users\MyUser\Source\Repos\MyProject\node_modules\fs.ts]
[C:\Users\MyUser\Source\Repos\MyProject\node_modules\fs.js]
 @ ./node_modules/node-gyp-build/index.js 1:9-22
 @ ./node_modules/win-sso/dist/win-sso.js
 @ ./node_modules/win-sso/dist/index.js
 @ ./node_modules/cypress-ntlm-auth/dist/util/sso.config.validator.js
 @ ./node_modules/cypress-ntlm-auth/dist/commands/index.js
 @ ./cypress/support/index.ts

I have experimenting with using both: 'npx cypress-ntlm open' and 'cypress-ntlm open'

I am on windows 10, Node 14.15.1

bjowes commented 3 years ago

Thanks for reporting @davidhel . I could reproduce an issue on my Mac (not the same error message but still), I will investigate.

bjowes commented 3 years ago

Cypress runs in two parts - one part is a node process (test runner and UI) and the other part is in the browser. Apparently Webpack tries to include modules which were intended for the node process only in the browser part when using my plugin. The same issue will likely occur with other plugins using native modules (such as fs) directly or indirectly.

In this case, I think the best solution is if proper config is set in the node-gyp-build module (which is indirectly used by this plugin), hence letting webpack know that fs (and a few other modules) won't be needed in the browser. I'll raise an issue with them about it.

In the mean time, you can make this work by manually editing the file node_modules/node_gyp_build/package.json and adding this section


"browser": {
    "fs": false,
    "os": false,
    "path": false
 },
davidhel commented 3 years ago

Thank you so much for this, that fixed the error.

bjowes commented 3 years ago

Found another way around this which could be implemented directly in my plugin. Release pending shortly.

rahul13425 commented 2 years ago

please resolve this

Error: Webpack Compilation Error ./cypress/integration/Assertion_Demo.js Module not found: Error: Can't resolve 'cypress/types/jquery' in 'D:\cyprees\tx_cyprees_Demo\cypress\integration' resolve 'cypress/types/jquery' in 'D:\cyprees\tx_cyprees_Demo\cypress\integration' Parsed request is a module using description file: D:\cyprees\tx_cyprees_Demo\package.json (relative path: ./cypress/integration) Field 'browser' doesn't contain a valid alias configuration Looked for and couldn't find the file at the following paths: [D:\cyprees\tx_cyprees_Demo\cypress\integration\node_modules] [D:\cyprees\tx_cyprees_Demo\cypress\node_modules] [D:\cyprees\node_modules] [D:\node_modules] [D:\cyprees\tx_cyprees_Demo\node_modules\cypress\types\jquery] [D:\cyprees\tx_cyprees_Demo\node_modules\cypress\types\jquery.js] [D:\cyprees\tx_cyprees_Demo\node_modules\cypress\types\jquery.json] [D:\cyprees\tx_cyprees_Demo\node_modules\cypress\types\jquery.jsx] [D:\cyprees\tx_cyprees_Demo\node_modules\cypress\types\jquery.mjs] [D:\cyprees\tx_cyprees_Demo\node_modules\cypress\types\jquery.coffee] [D:\cyprees\tx_cyprees_Demo\node_modules\cypress\types\jquery\index] [D:\cyprees\tx_cyprees_Demo\node_modules\cypress\types\jquery\index.js] [D:\cyprees\tx_cyprees_Demo\node_modules\cypress\types\jquery\index.json] [D:\cyprees\tx_cyprees_Demo\node_modules\cypress\types\jquery\index.jsx] [D:\cyprees\tx_cyprees_Demo\node_modules\cypress\types\jquery\index.mjs] [D:\cyprees\tx_cyprees_Demo\node_modules\cypress\types\jquery\index.coffee] @ ./cypress/integration/Assertion_Demo.js 6:4-35

at Watching.handle [as handler] (C:\Users\HP\AppData\Local\Cypress\Cache\9.5.0\Cypress\resources\app\packages\server\node_modules\@cypress\webpack-preprocessor\dist\index.js:180:23)
at C:\Users\HP\AppData\Local\Cypress\Cache\9.5.0\Cypress\resources\app\node_modules\webpack\lib\Watching.js:99:9
at AsyncSeriesHook.eval [as callAsync] (eval at create (C:\Users\HP\AppData\Local\Cypress\Cache\9.5.0\Cypress\resources\app\node_modules\tapable\lib\HookCodeFactory.js:33:10), <anonymous>:6:1)
at AsyncSeriesHook.lazyCompileHook (C:\Users\HP\AppData\Local\Cypress\Cache\9.5.0\Cypress\resources\app\node_modules\tapable\lib\Hook.js:154:20)
at Watching._done (C:\Users\HP\AppData\Local\Cypress\Cache\9.5.0\Cypress\resources\app\node_modules\webpack\lib\Watching.js:98:28)
at C:\Users\HP\AppData\Local\Cypress\Cache\9.5.0\Cypress\resources\app\node_modules\webpack\lib\Watching.js:73:19
at Compiler.emitRecords (C:\Users\HP\AppData\Local\Cypress\Cache\9.5.0\Cypress\resources\app\node_modules\webpack\lib\Compiler.js:499:39)
at C:\Users\HP\AppData\Local\Cypress\Cache\9.5.0\Cypress\resources\app\node_modules\webpack\lib\Watching.js:54:20
at C:\Users\HP\AppData\Local\Cypress\Cache\9.5.0\Cypress\resources\app\node_modules\webpack\lib\Compiler.js:485:14
at AsyncSeriesHook.eval [as callAsync] (eval at create (C:\Users\HP\AppData\Local\Cypress\Cache\9.5.0\Cypress\resources\app\node_modules\tapable\lib\HookCodeFactory.js:33:10), <anonymous>:6:1)
at AsyncSeriesHook.lazyCompileHook (C:\Users\HP\AppData\Local\Cypress\Cache\9.5.0\Cypress\resources\app\node_modules\tapable\lib\Hook.js:154:20)
at C:\Users\HP\AppData\Local\Cypress\Cache\9.5.0\Cypress\resources\app\node_modules\webpack\lib\Compiler.js:482:27
at C:\Users\HP\AppData\Local\Cypress\Cache\9.5.0\Cypress\resources\app\node_modules\neo-async\async.js:2818:7
at done (C:\Users\HP\AppData\Local\Cypress\Cache\9.5.0\Cypress\resources\app\node_modules\neo-async\async.js:3522:9)
at AsyncSeriesHook.eval [as callAsync] (eval at create (C:\Users\HP\AppData\Local\Cypress\Cache\9.5.0\Cypress\resources\app\node_modules\tapable\lib\HookCodeFactory.js:33:10), <anonymous>:6:1)
at AsyncSeriesHook.lazyCompileHook (C:\Users\HP\AppData\Local\Cypress\Cache\9.5.0\Cypress\resources\app\node_modules\tapable\lib\Hook.js:154:20)
at C:\Users\HP\AppData\Local\Cypress\Cache\9.5.0\Cypress\resources\app\node_modules\webpack\lib\Compiler.js:464:33
at C:\Users\HP\AppData\Local\Cypress\Cache\9.5.0\Cypress\resources\app\node_modules\graceful-fs\graceful-fs.js:143:16
at C:\Users\HP\AppData\Local\Cypress\Cache\9.5.0\Cypress\resources\app\node_modules\graceful-fs\graceful-fs.js:61:14
at FSReqCallback.oncomplete (node:fs:188:23)

2022-02-17 ![Uploading 2022-02-17.png…]()

bjowes commented 2 years ago

Just a hunch - try downgrading to cypress-ntlm-auth 3.2.3

On Thu, Feb 17, 2022 at 10:04 AM rahul13425 @.***> wrote:

please resolve this

Error: Webpack Compilation Error ./cypress/integration/Assertion_Demo.js Module not found: Error: Can't resolve 'cypress/types/jquery' in 'D:\cyprees\tx_cyprees_Demo\cypress\integration' resolve 'cypress/types/jquery' in 'D:\cyprees\tx_cyprees_Demo\cypress\integration' Parsed request is a module using description file: D:\cyprees\tx_cyprees_Demo\package.json (relative path: ./cypress/integration) Field 'browser' doesn't contain a valid alias configuration Looked for and couldn't find the file at the following paths: [D:\cyprees\tx_cyprees_Demo\cypress\integration\node_modules] [D:\cyprees\tx_cyprees_Demo\cypress\node_modules] [D:\cyprees\node_modules] [D:\node_modules] [D:\cyprees\tx_cyprees_Demo\node_modules\cypress\types\jquery] [D:\cyprees\tx_cyprees_Demo\node_modules\cypress\types\jquery.js] [D:\cyprees\tx_cyprees_Demo\node_modules\cypress\types\jquery.json] [D:\cyprees\tx_cyprees_Demo\node_modules\cypress\types\jquery.jsx] [D:\cyprees\tx_cyprees_Demo\node_modules\cypress\types\jquery.mjs] [D:\cyprees\tx_cyprees_Demo\node_modules\cypress\types\jquery.coffee] [D:\cyprees\tx_cyprees_Demo\node_modules\cypress\types\jquery\index] [D:\cyprees\tx_cyprees_Demo\node_modules\cypress\types\jquery\index.js] [D:\cyprees\tx_cyprees_Demo\node_modules\cypress\types\jquery\index.json] [D:\cyprees\tx_cyprees_Demo\node_modules\cypress\types\jquery\index.jsx] [D:\cyprees\tx_cyprees_Demo\node_modules\cypress\types\jquery\index.mjs] [D:\cyprees\tx_cyprees_Demo\node_modules\cypress\types\jquery\index.coffee] @ ./cypress/integration/Assertion_Demo.js 6:4-35

at Watching.handle [as handler] @.***\webpack-preprocessor\dist\index.js:180:23)

at C:\Users\HP\AppData\Local\Cypress\Cache\9.5.0\Cypress\resources\app\node_modules\webpack\lib\Watching.js:99:9

at AsyncSeriesHook.eval [as callAsync] (eval at create (C:\Users\HP\AppData\Local\Cypress\Cache\9.5.0\Cypress\resources\app\node_modules\tapable\lib\HookCodeFactory.js:33:10), :6:1)

at AsyncSeriesHook.lazyCompileHook (C:\Users\HP\AppData\Local\Cypress\Cache\9.5.0\Cypress\resources\app\node_modules\tapable\lib\Hook.js:154:20)

at Watching._done (C:\Users\HP\AppData\Local\Cypress\Cache\9.5.0\Cypress\resources\app\node_modules\webpack\lib\Watching.js:98:28)

at C:\Users\HP\AppData\Local\Cypress\Cache\9.5.0\Cypress\resources\app\node_modules\webpack\lib\Watching.js:73:19

at Compiler.emitRecords (C:\Users\HP\AppData\Local\Cypress\Cache\9.5.0\Cypress\resources\app\node_modules\webpack\lib\Compiler.js:499:39)

at C:\Users\HP\AppData\Local\Cypress\Cache\9.5.0\Cypress\resources\app\node_modules\webpack\lib\Watching.js:54:20

at C:\Users\HP\AppData\Local\Cypress\Cache\9.5.0\Cypress\resources\app\node_modules\webpack\lib\Compiler.js:485:14

at AsyncSeriesHook.eval [as callAsync] (eval at create (C:\Users\HP\AppData\Local\Cypress\Cache\9.5.0\Cypress\resources\app\node_modules\tapable\lib\HookCodeFactory.js:33:10), :6:1)

at AsyncSeriesHook.lazyCompileHook (C:\Users\HP\AppData\Local\Cypress\Cache\9.5.0\Cypress\resources\app\node_modules\tapable\lib\Hook.js:154:20)

at C:\Users\HP\AppData\Local\Cypress\Cache\9.5.0\Cypress\resources\app\node_modules\webpack\lib\Compiler.js:482:27

at C:\Users\HP\AppData\Local\Cypress\Cache\9.5.0\Cypress\resources\app\node_modules\neo-async\async.js:2818:7

at done (C:\Users\HP\AppData\Local\Cypress\Cache\9.5.0\Cypress\resources\app\node_modules\neo-async\async.js:3522:9)

at AsyncSeriesHook.eval [as callAsync] (eval at create (C:\Users\HP\AppData\Local\Cypress\Cache\9.5.0\Cypress\resources\app\node_modules\tapable\lib\HookCodeFactory.js:33:10), :6:1)

at AsyncSeriesHook.lazyCompileHook (C:\Users\HP\AppData\Local\Cypress\Cache\9.5.0\Cypress\resources\app\node_modules\tapable\lib\Hook.js:154:20)

at C:\Users\HP\AppData\Local\Cypress\Cache\9.5.0\Cypress\resources\app\node_modules\webpack\lib\Compiler.js:464:33

at C:\Users\HP\AppData\Local\Cypress\Cache\9.5.0\Cypress\resources\app\node_modules\graceful-fs\graceful-fs.js:143:16

at C:\Users\HP\AppData\Local\Cypress\Cache\9.5.0\Cypress\resources\app\node_modules\graceful-fs\graceful-fs.js:61:14

at FSReqCallback.oncomplete (node:fs:188:23)

[image: 2022-02-17] https://user-images.githubusercontent.com/99000780/154441895-c1b68b28-27c4-4a79-aa99-e47095ad22e5.png [image: Uploading 2022-02-17.png…]

— Reply to this email directly, view it on GitHub https://github.com/bjowes/cypress-ntlm-auth/issues/159#issuecomment-1042720247, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABCHR3G5KVDME6IMCPRJHVDU3S23HANCNFSM4XE7MKZQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you modified the open/close state.Message ID: @.***>

bjowes commented 2 years ago

@rahul13425 - The latest release of the plugin, 3.2.6, has reverted to packaging JS into a CommonJs module. Hence it behaves as the old versions. If that was indeed the issue you were facing you can upgrade to latest again.