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

E2E Tests do not support the exports field from external modules #23826

Open
nbouvrette opened this issue Sep 14, 2022 · 3 comments
Open

E2E Tests do not support the exports field from external modules #23826

nbouvrette opened this issue Sep 14, 2022 · 3 comments
Labels
E2E Issue related to end-to-end testing existing workaround npm: webpack-batteries-included-preprocessor @cypress/webpack-batteries-included-preprocessor package issues Triaged Issue has been routed to backlog. This is not a commitment to have it prioritized by the team.

Comments

@nbouvrette
Copy link

Current behavior

I'm writing an E2E test for Next.js and I am trying to do the following in one of my tests:

import { propertiesToJson } from "properties-file/content";
console.dir(propertiesToJson("hello: world"));

The test fails with the following unclear Webpack error which from what I understood means "package is not found":

Error: Webpack Compilation Error
./cypress/e2e/app.cy.ts
Module not found: Error: Can't resolve 'properties-file/content' in '/Projects/with-cypress-app/cypress/e2e'
resolve 'properties-file/content' in '/Projects/with-cypress-app/cypress/e2e'
  Parsed request is a module
  using description file: /Projects/with-cypress-app/package.json (relative path: ./cypress/e2e)
    Field 'browser' doesn't contain a valid alias configuration
    Looked for and couldn't find the file at the following paths:
[/Projects/with-cypress-app/cypress/e2e/node_modules]
[/Projects/with-cypress-app/cypress/node_modules]
[/Projects/node_modules]
[/node_modules]
[/Users/node_modules]
[/node_modules]
[/Projects/with-cypress-app/node_modules/properties-file/content]
[/Projects/with-cypress-app/node_modules/properties-file/content.js]
[/Projects/with-cypress-app/node_modules/properties-file/content.json]
[/Projects/with-cypress-app/node_modules/properties-file/content.jsx]
[/Projects/with-cypress-app/node_modules/properties-file/content.mjs]
[/Projects/with-cypress-app/node_modules/properties-file/content.coffee]
[/Projects/with-cypress-app/node_modules/properties-file/content.ts]
[/Projects/with-cypress-app/node_modules/properties-file/content.tsx]
 @ ./cypress/e2e/app.cy.ts 8:16-50
 
    at Watching.handle [as handler] (/Library/Caches/Cypress/10.3.1/Cypress.app/Contents/Resources/app/packages/server/node_modules/@cypress/webpack-preprocessor/dist/index.js:180:23)
    at /Library/Caches/Cypress/10.3.1/Cypress.app/Contents/Resources/app/node_modules/webpack/lib/Watching.js:99:9
    at AsyncSeriesHook.eval [as callAsync] (eval at create (/Library/Caches/Cypress/10.3.1/Cypress.app/Contents/Resources/app/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
    at Watching._done (/Library/Caches/Cypress/10.3.1/Cypress.app/Contents/Resources/app/node_modules/webpack/lib/Watching.js:98:28)
    at /Library/Caches/Cypress/10.3.1/Cypress.app/Contents/Resources/app/node_modules/webpack/lib/Watching.js:73:19
    at Compiler.emitRecords (/Library/Caches/Cypress/10.3.1/Cypress.app/Contents/Resources/app/node_modules/webpack/lib/Compiler.js:499:39)
    at /Library/Caches/Cypress/10.3.1/Cypress.app/Contents/Resources/app/node_modules/webpack/lib/Watching.js:54:20
    at /Library/Caches/Cypress/10.3.1/Cypress.app/Contents/Resources/app/node_modules/webpack/lib/Compiler.js:485:14
    at AsyncSeriesHook.eval [as callAsync] (eval at create (/Library/Caches/Cypress/10.3.1/Cypress.app/Contents/Resources/app/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
    at /Library/Caches/Cypress/10.3.1/Cypress.app/Contents/Resources/app/node_modules/webpack/lib/Compiler.js:482:27
    at /Library/Caches/Cypress/10.3.1/Cypress.app/Contents/Resources/app/node_modules/neo-async/async.js:2818:7
    at done (/Library/Caches/Cypress/10.3.1/Cypress.app/Contents/Resources/app/node_modules/neo-async/async.js:3522:9)
    at AsyncSeriesHook.eval [as callAsync] (eval at create (/Library/Caches/Cypress/10.3.1/Cypress.app/Contents/Resources/app/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
    at /Library/Caches/Cypress/10.3.1/Cypress.app/Contents/Resources/app/node_modules/webpack/lib/Compiler.js:464:33
    at /Library/Caches/Cypress/10.3.1/Cypress.app/Contents/Resources/app/packages/server/node_modules/graceful-fs/graceful-fs.js:143:16
    at /Library/Caches/Cypress/10.3.1/Cypress.app/Contents/Resources/app/packages/server/node_modules/graceful-fs/graceful-fs.js:143:16
    at /Library/Caches/Cypress/10.3.1/Cypress.app/Contents/Resources/app/packages/server/node_modules/graceful-fs/graceful-fs.js:61:14
    at FSReqCallback.oncomplete (node:fs:196:23)

I can make this work using the following workaround, bypassing the exports configuration from the package.

import { propertiesToJson } from "properties-file/lib/content/index";
console.dir(propertiesToJson("hello: world"));

Desired behavior

Importing a package using exports should work like any other Node.js application.

Test code to reproduce

  1. npx create-next-app --example with-cypress with-cypress-app
  2. npm install properties-file
  3. add the following code in /cypress/e2e/app.cy.ts:
import { propertiesToJson } from "properties-file/content";
// import { propertiesToJson } from "properties-file/lib/content/index";
// import { propertiesToJson } from "../../node_modules/properties-file/lib/content/index";
console.dir(propertiesToJson("hello: world"));
  1. Test the different ways to import and see the issue when using the first (uncommented) option.

Cypress Version

10.8.0

Node version

v16.17.0

Operating System

macOS 12.5.1

Debug Logs

[./cypress/support/e2e.ts] 746 bytes {main} [built]
  cypress:webpack - compile finished for /Projects/with-cypress-app/cypress/support/e2e.ts, initial? true +23ms
  cypress:lifecycle:ProjectConfigManager promise resolved for id 'inv5' with value /Library/Application Support/Cypress/cy/production/projects/with-cypress-app-b18dd29a6245325853b918353967215b/bundles/cypress/support/e2e.ts.js +151ms
  cypress:server:controllers:spec sending spec { filePath: '/Library/Application Support/Cypress/cy/production/projects/with-cypress-app-b18dd29a6245325853b918353967215b/bundles/cypress/support/e2e.ts.js' } +151ms
GET /__cypress/tests?p=cypress/support/e2e.ts 200 152.104 ms - -
  cypress:webpack stats had error(s) [ './cypress/e2e/app.cy.ts\n' + "Module not found: Error: Can't resolve 'properties-file/content' in '/Projects/with-cypress-app/cypress/e2e'\n" + "resolve 'properties-file/content' in '/Projects/with-cypress-app/cypress/e2e'\n" + '  Parsed request is a module\n' + '  using description file: /Projects/with-cypress-app/package.json (relative path: ./cypress/e2e)\n' + "    Field 'browser' doesn't contain a valid alias configuration\n" + '    resolve as module\n' + "      /Projects/with-cypress-app/cypress/e2e/node_modules doesn't exist or is not a directory\n" + "      /Projects/with-cypress-app/cypress/node_modules doesn't exist or is not a directory\n" + "      /Projects/node_modules doesn't exist or is not a directory\n" + "      /node_modules doesn't exist or is not a directory\n" + "      /Users/node_modules doesn't exist or is not a directory\n" + "      /node_modules doesn't exist or is not a directory\n" + '      looking for modules in /Projects/with-cypress-app/node_modules\n' + '        using description file: /Projects/with-cypress-app/package.json (relative path: ./node_modules)\n' + "          Field 'browser' doesn't contain a valid alias configuration\n" + '          using description file: /Projects/with-cypress-app/node_modules/properties-file/package.json (relative path: ./content)\n' + '            no extension\n' + "              Field 'browser' doesn't contain a valid alias configuration\n" + "              /Projects/with-cypress-app/node_modules/properties-file/content doesn't exist\n" + '            .js\n' + "              Field 'browser' doesn't contain a valid alias configuration\n" + "              /Projects/with-cypress-app/node_modules/properties-file/content.js doesn't exist\n" + '            .json\n' + "              Field 'browser' doesn't contain a valid alias configuration\n" + "              /Projects/with-cypress-app/node_modules/properties-file/content.json doesn't exist\n" + '            .jsx\n' + "              Field 'browser' doesn't contain a valid alias configuration\n" + "              /Projects/with-cypress-app/node_modules/properties-file/content.jsx doesn't exist\n" + '            .mjs\n' + "              Field 'browser' doesn't contain a valid alias configuration\n" + "              /Projects/with-cypress-app/node_modules/properties-file/content.mjs doesn't exist\n" + '            .coffee\n' + "              Field 'browser' doesn't contain a valid alias configuration\n" + "              /Projects/with-cypress-app/node_modules/properties-file/content.coffee doesn't exist\n" + '            .ts\n' + "              Field 'browser' doesn't contain a valid alias configuration\n" + "              /Projects/with-cypress-app/node_modules/properties-file/content.ts doesn't exist\n" + '            .tsx\n' + "              Field 'browser' doesn't contain a valid alias configuration\n" + "              /Projects/with-cypress-app/node_modules/properties-file/content.tsx doesn't exist\n" + '            as directory\n' + "              /Projects/with-cypress-app/node_modules/properties-file/content doesn't exist\n" + '[/Projects/with-cypress-app/cypress/e2e/node_modules]\n' + '[/Projects/with-cypress-app/cypress/node_modules]\n' + '[/Projects/node_modules]\n' + '[/node_modules]\n' + '[/Users/node_modules]\n' + '[/node_modules]\n' + '[/Projects/with-cypress-app/node_modules/properties-file/content]\n' + '[/Projects/with-cypress-app/node_modules/properties-file/content.js]\n' + '[/Projects/with-cypress-app/node_modules/properties-file/content.json]\n' + '[/Projects/with-cypress-app/node_modules/properties-file/content.jsx]\n' + '[/Projects/with-cypress-app/node_modules/properties-file/content.mjs]\n' + '[/Projects/with-cypress-app/node_modules/properties-file/content.coffee]\n' + '[/Projects/with-cypress-app/node_modules/properties-file/content.ts]\n' + '[/Projects/with-cypress-app/node_modules/properties-file/content.tsx]\n' + ' @ ./cypress/e2e/app.cy.ts 8:16-50\n' + ' @ multi ./cypress/e2e/app.cy.ts' ] +17ms
  cypress:webpack errored bundling /Library/Application Support/Cypress/cy/production/projects/with-cypress-app-b18dd29a6245325853b918353967215b/bundles/cypress/e2e/app.cy.ts.js Webpack Compilation Error
./cypress/e2e/app.cy.ts
Module not found: Error: Can't resolve 'properties-file/content' in '/Projects/with-cypress-app/cypress/e2e'
resolve 'properties-file/content' in '/Projects/with-cypress-app/cypress/e2e'
  Parsed request is a module
  using description file: /Projects/with-cypress-app/package.json (relative path: ./cypress/e2e)
    Field 'browser' doesn't contain a valid alias configuration
    Looked for and couldn't find the file at the following paths:
[/Projects/with-cypress-app/cypress/e2e/node_modules]
[/Projects/with-cypress-app/cypress/node_modules]
[/Projects/node_modules]
[/node_modules]
[/Users/node_modules]
[/node_modules]
[/Projects/with-cypress-app/node_modules/properties-file/content]
[/Projects/with-cypress-app/node_modules/properties-file/content.js]
[/Projects/with-cypress-app/node_modules/properties-file/content.json]
[/Projects/with-cypress-app/node_modules/properties-file/content.jsx]
[/Projects/with-cypress-app/node_modules/properties-file/content.mjs]
[/Projects/with-cypress-app/node_modules/properties-file/content.coffee]
[/Projects/with-cypress-app/node_modules/properties-file/content.ts]
[/Projects/with-cypress-app/node_modules/properties-file/content.tsx]
 @ ./cypress/e2e/app.cy.ts 8:16-50 +3ms
  cypress:webpack - compile finished for /Projects/with-cypress-app/cypress/e2e/app.cy.ts, initial? true +1ms
  cypress:lifecycle:ProjectConfigManager promise rejected for id inv4 ':' Error: Webpack Compilation Error
./cypress/e2e/app.cy.ts
Module not found: Error: Can't resolve 'properties-file/content' in '/Projects/with-cypress-app/cypress/e2e'
resolve 'properties-file/content' in '/Projects/with-cypress-app/cypress/e2e'
  Parsed request is a module
  using description file: /Projects/with-cypress-app/package.json (relative path: ./cypress/e2e)
    Field 'browser' doesn't contain a valid alias configuration
    Looked for and couldn't find the file at the following paths:
[/Projects/with-cypress-app/cypress/e2e/node_modules]
[/Projects/with-cypress-app/cypress/node_modules]
[/Projects/node_modules]
[/node_modules]
[/Users/node_modules]
[/node_modules]
[/Projects/with-cypress-app/node_modules/properties-file/content]
[/Projects/with-cypress-app/node_modules/properties-file/content.js]
[/Projects/with-cypress-app/node_modules/properties-file/content.json]
[/Projects/with-cypress-app/node_modules/properties-file/content.jsx]
[/Projects/with-cypress-app/node_modules/properties-file/content.mjs]
[/Projects/with-cypress-app/node_modules/properties-file/content.coffee]
[/Projects/with-cypress-app/node_modules/properties-file/content.ts]
[/Projects/with-cypress-app/node_modules/properties-file/content.tsx]
 @ ./cypress/e2e/app.cy.ts 8:16-50
 
    at Watching.handle [as handler] (/Library/Caches/Cypress/10.8.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/@cypress/webpack-preprocessor/dist/index.js:180:23)
    at /Library/Caches/Cypress/10.8.0/Cypress.app/Contents/Resources/app/node_modules/webpack/lib/Watching.js:99:9
    at AsyncSeriesHook.eval [as callAsync] (eval at create (/Library/Caches/Cypress/10.8.0/Cypress.app/Contents/Resources/app/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
    at AsyncSeriesHook.lazyCompileHook (/Library/Caches/Cypress/10.8.0/Cypress.app/Contents/Resources/app/node_modules/tapable/lib/Hook.js:154:20)
    at Watching._done (/Library/Caches/Cypress/10.8.0/Cypress.app/Contents/Resources/app/node_modules/webpack/lib/Watching.js:98:28)
    at /Library/Caches/Cypress/10.8.0/Cypress.app/Contents/Resources/app/node_modules/webpack/lib/Watching.js:73:19
    at Compiler.emitRecords (/Library/Caches/Cypress/10.8.0/Cypress.app/Contents/Resources/app/node_modules/webpack/lib/Compiler.js:499:39)
    at /Library/Caches/Cypress/10.8.0/Cypress.app/Contents/Resources/app/node_modules/webpack/lib/Watching.js:54:20
    at /Library/Caches/Cypress/10.8.0/Cypress.app/Contents/Resources/app/node_modules/webpack/lib/Compiler.js:485:14
    at AsyncSeriesHook.eval [as callAsync] (eval at create (/Library/Caches/Cypress/10.8.0/Cypress.app/Contents/Resources/app/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
    at AsyncSeriesHook.lazyCompileHook (/Library/Caches/Cypress/10.8.0/Cypress.app/Contents/Resources/app/node_modules/tapable/lib/Hook.js:154:20)
    at /Library/Caches/Cypress/10.8.0/Cypress.app/Contents/Resources/app/node_modules/webpack/lib/Compiler.js:482:27
    at /Library/Caches/Cypress/10.8.0/Cypress.app/Contents/Resources/app/node_modules/neo-async/async.js:2818:7
    at done (/Library/Caches/Cypress/10.8.0/Cypress.app/Contents/Resources/app/node_modules/neo-async/async.js:3522:9)
    at AsyncSeriesHook.eval [as callAsync] (eval at create (/Library/Caches/Cypress/10.8.0/Cypress.app/Contents/Resources/app/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
    at AsyncSeriesHook.lazyCompileHook (/Library/Caches/Cypress/10.8.0/Cypress.app/Contents/Resources/app/node_modules/tapable/lib/Hook.js:154:20)
    at /Library/Caches/Cypress/10.8.0/Cypress.app/Contents/Resources/app/node_modules/webpack/lib/Compiler.js:464:33
    at /Library/Caches/Cypress/10.8.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/graceful-fs/graceful-fs.js:143:16
    at /Library/Caches/Cypress/10.8.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/graceful-fs/graceful-fs.js:143:16
    at /Library/Caches/Cypress/10.8.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/graceful-fs/graceful-fs.js:61:14
    at FSReqCallback.oncomplete (node:fs:196:23) +24ms
  cypress:lifecycle:ProjectConfigManager promise rejected for id inv6 ':' Error: Webpack Compilation Error
./cypress/e2e/app.cy.ts
Module not found: Error: Can't resolve 'properties-file/content' in '/Projects/with-cypress-app/cypress/e2e'
resolve 'properties-file/content' in '/Projects/with-cypress-app/cypress/e2e'
  Parsed request is a module
  using description file: /Projects/with-cypress-app/package.json (relative path: ./cypress/e2e)
    Field 'browser' doesn't contain a valid alias configuration
    Looked for and couldn't find the file at the following paths:
[/Projects/with-cypress-app/cypress/e2e/node_modules]
[/Projects/with-cypress-app/cypress/node_modules]
[/Projects/node_modules]
[/node_modules]
[/Users/node_modules]
[/node_modules]
[/Projects/with-cypress-app/node_modules/properties-file/content]
[/Projects/with-cypress-app/node_modules/properties-file/content.js]
[/Projects/with-cypress-app/node_modules/properties-file/content.json]
[/Projects/with-cypress-app/node_modules/properties-file/content.jsx]
[/Projects/with-cypress-app/node_modules/properties-file/content.mjs]
[/Projects/with-cypress-app/node_modules/properties-file/content.coffee]
[/Projects/with-cypress-app/node_modules/properties-file/content.ts]
[/Projects/with-cypress-app/node_modules/properties-file/content.tsx]
 @ ./cypress/e2e/app.cy.ts 8:16-50
 
    at Watching.handle [as handler] (/Library/Caches/Cypress/10.8.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/@cypress/webpack-preprocessor/dist/index.js:180:23)
    at /Library/Caches/Cypress/10.8.0/Cypress.app/Contents/Resources/app/node_modules/webpack/lib/Watching.js:99:9
    at AsyncSeriesHook.eval [as callAsync] (eval at create (/Library/Caches/Cypress/10.8.0/Cypress.app/Contents/Resources/app/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
    at AsyncSeriesHook.lazyCompileHook (/Library/Caches/Cypress/10.8.0/Cypress.app/Contents/Resources/app/node_modules/tapable/lib/Hook.js:154:20)
    at Watching._done (/Library/Caches/Cypress/10.8.0/Cypress.app/Contents/Resources/app/node_modules/webpack/lib/Watching.js:98:28)
    at /Library/Caches/Cypress/10.8.0/Cypress.app/Contents/Resources/app/node_modules/webpack/lib/Watching.js:73:19
    at Compiler.emitRecords (/Library/Caches/Cypress/10.8.0/Cypress.app/Contents/Resources/app/node_modules/webpack/lib/Compiler.js:499:39)
    at /Library/Caches/Cypress/10.8.0/Cypress.app/Contents/Resources/app/node_modules/webpack/lib/Watching.js:54:20
    at /Library/Caches/Cypress/10.8.0/Cypress.app/Contents/Resources/app/node_modules/webpack/lib/Compiler.js:485:14
    at AsyncSeriesHook.eval [as callAsync] (eval at create (/Library/Caches/Cypress/10.8.0/Cypress.app/Contents/Resources/app/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
    at AsyncSeriesHook.lazyCompileHook (/Library/Caches/Cypress/10.8.0/Cypress.app/Contents/Resources/app/node_modules/tapable/lib/Hook.js:154:20)
    at /Library/Caches/Cypress/10.8.0/Cypress.app/Contents/Resources/app/node_modules/webpack/lib/Compiler.js:482:27
    at /Library/Caches/Cypress/10.8.0/Cypress.app/Contents/Resources/app/node_modules/neo-async/async.js:2818:7
    at done (/Library/Caches/Cypress/10.8.0/Cypress.app/Contents/Resources/app/node_modules/neo-async/async.js:3522:9)
    at AsyncSeriesHook.eval [as callAsync] (eval at create (/Library/Caches/Cypress/10.8.0/Cypress.app/Contents/Resources/app/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
    at AsyncSeriesHook.lazyCompileHook (/Library/Caches/Cypress/10.8.0/Cypress.app/Contents/Resources/app/node_modules/tapable/lib/Hook.js:154:20)
    at /Library/Caches/Cypress/10.8.0/Cypress.app/Contents/Resources/app/node_modules/webpack/lib/Compiler.js:464:33
    at /Library/Caches/Cypress/10.8.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/graceful-fs/graceful-fs.js:143:16
    at /Library/Caches/Cypress/10.8.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/graceful-fs/graceful-fs.js:143:16
    at /Library/Caches/Cypress/10.8.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/graceful-fs/graceful-fs.js:61:14
    at FSReqCallback.oncomplete (node:fs:196:23) +1ms
  cypress:server:controllers:spec preprocessor error for spec 'cypress/e2e/app.cy.ts': Error: Webpack Compilation Error
./cypress/e2e/app.cy.ts
Module not found: Error: Can't resolve 'properties-file/content' in '/Projects/with-cypress-app/cypress/e2e'
resolve 'properties-file/content' in '/Projects/with-cypress-app/cypress/e2e'
  Parsed request is a module
  using description file: /Projects/with-cypress-app/package.json (relative path: ./cypress/e2e)
    Field 'browser' doesn't contain a valid alias configuration
    Looked for and couldn't find the file at the following paths:
[/Projects/with-cypress-app/cypress/e2e/node_modules]
[/Projects/with-cypress-app/cypress/node_modules]
[/Projects/node_modules]
[/node_modules]
[/Users/node_modules]
[/node_modules]
[/Projects/with-cypress-app/node_modules/properties-file/content]
[/PrWebpack Compilation Error
./cypress/e2e/app.cy.ts
Module not found: Error: Can't resolve 'properties-file/content' in '/Projects/with-cypress-app/cypress/e2e'
resolve 'properties-file/content' in '/Projects/with-cypress-app/cypress/e2e'
  Parsed request is a module
  using description file: /Projects/with-cypress-app/package.json (relative path: ./cypress/e2e)
    Field 'browser' doesn't contain a valid alias configuration
    Looked for and couldn't find the file at the following paths:
[/Projects/with-cypress-app/cypress/e2e/node_modules]
[/Projects/with-cypress-app/cypress/node_modules]
[/Projects/node_modules]
[/node_modules]
[/Users/node_modules]
[/node_modules]
[/Projects/with-cypress-app/node_modules/properties-file/content]
[/Projects/with-cypress-app/node_modules/properties-file/content.js]
[/Projects/with-cypress-app/node_modules/properties-file/content.json]
[/Projects/with-cypress-app/node_modules/properties-file/content.jsx]
[/Projects/with-cypress-app/node_modules/properties-file/content.mjs]
[/Projects/with-cypress-app/node_modules/properties-file/content.coffee]
[/Projects/with-cypress-app/node_modules/properties-file/content.ts]
[/Projects/with-cypress-app/node_modules/properties-file/content.tsx]
 @ ./cypress/e2e/app.cy.ts 8:16-50
ojects/with-cypress-app/node_modules/properties-file/content.js]
[/Projects/with-cypress-app/node_modules/properties-file/content.json]
[/Projects/with-cypress-app/node_modules/properties-file/content.jsx]
[/Projects/with-cypress-app/node_modules/properties-file/content.mjs]
[/Projects/with-cypress-app/node_modules/properties-file/content.coffee]
[/Projects/with-cypress-app/node_modules/properties-file/content.ts]
[/Projects/with-cypress-app/node_modules/properties-file/content.tsx]
 @ ./cypress/e2e/app.cy.ts 8:16-50
 
    at Watching.handle [as handler] (/Library/Caches/Cypress/10.8.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/@cypress/webpack-preprocessor/dist/index.js:180:23)
    at /Library/Caches/Cypress/10.8.0/Cypress.app/Contents/Resources/app/node_modules/webpack/lib/Watching.js:99:9
    at AsyncSeriesHook.eval [as callAsync] (eval at create (/Library/Caches/Cypress/10.8.0/Cypress.app/Contents/Resources/app/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
    at AsyncSeriesHook.lazyCompileHook (/Library/Caches/Cypress/10.8.0/Cypress.app/Contents/Resources/app/node_modules/tapable/lib/Hook.js:154:20)
    at Watching._done (/Library/Caches/Cypress/10.8.0/Cypress.app/Contents/Resources/app/node_modules/webpack/lib/Watching.js:98:28)
    at /Library/Caches/Cypress/10.8.0/Cypress.app/Contents/Resources/app/node_modules/webpack/lib/Watching.js:73:19
    at Compiler.emitRecords (/Library/Caches/Cypress/10.8.0/Cypress.app/Contents/Resources/app/node_modules/webpack/lib/Compiler.js:499:39)
    at /Library/Caches/Cypress/10.8.0/Cypress.app/Contents/Resources/app/node_modules/webpack/lib/Watching.js:54:20
    at /Library/Caches/Cypress/10.8.0/Cypress.app/Contents/Resources/app/node_modules/webpack/lib/Compiler.js:485:14
    at AsyncSeriesHook.eval [as callAsync] (eval at create (/Library/Caches/Cypress/10.8.0/Cypress.app/Contents/Resources/app/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
    at AsyncSeriesHook.lazyCompileHook (/Library/Caches/Cypress/10.8.0/Cypress.app/Contents/Resources/app/node_modules/tapable/lib/Hook.js:154:20)
    at /Library/Caches/Cypress/10.8.0/Cypress.app/Contents/Resources/app/node_modules/webpack/lib/Compiler.js:482:27
    at /Library/Caches/Cypress/10.8.0/Cypress.app/Contents/Resources/app/node_modules/neo-async/async.js:2818:7
    at done (/Library/Caches/Cypress/10.8.0/Cypress.app/Contents/Resources/app/node_modules/neo-async/async.js:3522:9)
    at AsyncSeriesHook.eval [as callAsync] (eval at create (/Library/Caches/Cypress/10.8.0/Cypress.app/Contents/Resources/app/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
    at AsyncSeriesHook.lazyCompileHook (/Library/Caches/Cypress/10.8.0/Cypress.app/Contents/Resources/app/node_modules/tapable/lib/Hook.js:154:20)
    at /Library/Caches/Cypress/10.8.0/Cypress.app/Contents/Resources/app/node_modules/webpack/lib/Compiler.js:464:33
    at /Library/Caches/Cypress/10.8.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/graceful-fs/graceful-fs.js:143:16
    at /Library/Caches/Cypress/10.8.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/graceful-fs/graceful-fs.js:143:16
    at /Library/Caches/Cypress/10.8.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/graceful-fs/graceful-fs.js:61:14
    at FSReqCallback.oncomplete (node:fs:196:23) +25ms
GET /__cypress/tests?p=cypress/e2e/app.cy.ts 200 176.149 ms - -

Other

No response

@ZachJW34 ZachJW34 self-assigned this Sep 14, 2022
@ZachJW34 ZachJW34 added the stage: investigating Someone from Cypress is looking into this label Sep 14, 2022
@ZachJW34
Copy link
Contributor

Thanks for opening this issue @nbouvrette

Looking into this, I found this webpack issue. Support for respecting package.json.exports is only available for Webpack 5, and the webpack-preprocessor built into Cypress uses Webpack 4. We have an issue for upgrading to webpack 5: #19555 but cannot give you a timeline for when we will work on this upgrade.

You've already noted a workaround for this (by using the full path to the properties/file-content module), but thought I'd post another workaround that gives you the desired behavior.

You can use Webpack 5 as your preprocessor by downloading @cypress/webpack-batteries-included-preprocessor and the latest version of webpack. Steps to implement:

  • npm i -D @cypress/webpack-batteries-included-preprocessor webpack
  • Tell Cypress to use the new processor in your cypress.config.ts
       import { defineConfig } from "cypress";
       import wp from "@cypress/webpack-batteries-included-preprocessor";
         
         export default defineConfig({
           e2e: {
             baseUrl: "http://localhost:3000",
             setupNodeEvents(on, config) {
               on(
                 "file:preprocessor",
                 wp({ typescript: require.resolve("typescript") })
               );
             },
           },
         });

The processor will resolve the version of webpack you have installed in your project, and if you install >=5 it will fix the exports resolve path.

Going to leave open until we switch to using Webpack 5 internally.

@nbouvrette
Copy link
Author

Thanks for the suggestion - unfortunately, it looks like @cypress/webpack-batteries-included-preprocessor depends on Webpack 4 which hasn't been updated for almost 2 years now and includes GHSA-ww39-953v-wcq6

I think I will stick with my workaround for now and hopefully we can have Cypress on Webpack5 this year :)

@ZachJW34
Copy link
Contributor

The security vulnerability is not ideal, could be the driving force to push us to upgrade to webpack 5! Thanks for the info, going to post in the Webpack 5 issue and hopefully gets some traction.

@ZachJW34 ZachJW34 added npm: webpack-batteries-included-preprocessor @cypress/webpack-batteries-included-preprocessor package issues routed-to-e2e and removed stage: investigating Someone from Cypress is looking into this labels Sep 15, 2022
@nagash77 nagash77 added E2E Issue related to end-to-end testing Triaged Issue has been routed to backlog. This is not a commitment to have it prioritized by the team. and removed routed-to-e2e labels Apr 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E2E Issue related to end-to-end testing existing workaround npm: webpack-batteries-included-preprocessor @cypress/webpack-batteries-included-preprocessor package issues Triaged Issue has been routed to backlog. This is not a commitment to have it prioritized by the team.
Projects
None yet
Development

No branches or pull requests

3 participants