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

Cypress - Error: Webpack Compilation Error, Module parse failed: Unexpected token #15737

Closed
nemonemi opened this issue Mar 17, 2023 · 10 comments
Closed
Assignees
Labels
blocked: repro needed outdated scope: testing tools Issues related to Cypress / Jest / Playwright / Vitest support in Nx stale type: bug

Comments

@nemonemi
Copy link

nemonemi commented Mar 17, 2023

Current Behavior

Everything worked fine up until I abstracted a library from the app.

Now, everything works, except Cypress tests.

225959596-9a462f2d-9f06-4fa4-8529-89859619f6fc
225966774-2d585004-1d3d-4c34-b3fa-9f2e11564a7a

However, there are no missing dependencies or syntax errors. Builds pass without any issues, and the runtime also works as it should.

Expected Behavior

It should work as it did before.

GitHub Repo

No response

Steps to Reproduce

Nx Report

Node : 16.14.0
   OS   : linux x64
   yarn : 3.4.1
   
   nx                      : 15.8.6
   @nrwl/js                : 15.8.6
   @nrwl/jest              : 15.8.6
   @nrwl/linter            : 15.8.6
   @nrwl/workspace         : 15.8.6
   @nrwl/cli               : 15.8.6
   @nrwl/cypress           : 15.8.6
   @nrwl/devkit            : 15.8.6
   @nrwl/eslint-plugin-nx  : 15.8.6
   @nrwl/react             : 15.8.6
   @nrwl/rollup            : 15.8.6
   @nrwl/storybook         : 15.8.6
   @nrwl/tao               : 15.8.6
   @nrwl/web               : 15.8.6
   @nrwl/webpack           : 15.8.6
   @nrwl/schematics        : 8.12.11
   typescript              : 4.9.5

Failure Logs

Oops...we found an error preparing this test file:

  > src/e2e/test.spec.ts

The error was:

Error: Webpack Compilation Error
/home/path/libs/utilities/src/lib/jwt-token-provider.tsx 21:23
Module parse failed: Unexpected token (21:23)
File was processed with these loaders:
 * ../../../../../.cache/Cypress/12.8.0/Cypress/resources/app/node_modules/@packages/server/node_modules/ts-loader/index.js
You may need an additional loader to handle the result of these loaders.
|     }, [isUsingQASBackendInsteadOfLocalMock]);
|     if (isLocalDevelopment && isUsingQASBackendInsteadOfLocalMock) {
>         return token ? <JWTContext.Provider value={token}>{children}</JWTContext.Provider> : null;
|     }
|     return children;

Additional Information

@charleskoehl
Copy link

I had a similar error after migrating to 15.8.6. I had to downgrade to 15.8.5 and then the builds worked. No other code was changed.

@AgentEnder AgentEnder added the scope: testing tools Issues related to Cypress / Jest / Playwright / Vitest support in Nx label Mar 20, 2023
@nemonemi
Copy link
Author

nemonemi commented Mar 20, 2023

@charleskoehl thanks for chipping in,
but unfortunately, that did not solve the problem reported above for me.

I've also tried it with the 15.8.7, but no change.

@nemonemi
Copy link
Author

I've just noticed that if I exclude my newly generated library, that I've abstracted the code from the application to create it, then the tests start passing.
What should I configure in the application, or the library, to make the tests recognize the JSX coming from the library?

@charleskoehl
Copy link

This seems relevant: #15794

@nemonemi
Copy link
Author

It is not obvious to me that they are related.
I've managed to resolve my issue by splitting the code even further.

The reason why my problem was occurring is that I had a file that contained an exported Context and an exported Context provider.
After splitting them into two separate libraries, the problem went away, however, that is not how I'd like my code to be, and it is not evident why this problem occurs.

This error is not indicative of the exact problem and makes the debugging difficult and time-consuming.

Module parse failed: Unexpected token (21:23)
File was processed with these loaders:

@jaysoo jaysoo self-assigned this Mar 28, 2023
@jaysoo
Copy link
Member

jaysoo commented Mar 28, 2023

Just to confirm, this is a React app created through @nrwl/react with a Cypress test suite?

Can someone share their webpack.config.js that is having issues?

@nemonemi
Copy link
Author

nemonemi commented Mar 28, 2023

@jaysoo, that is correct.

module.exports = composePlugins(withNx(), withReact(), (config, { options, context }) => {
  return merge(config, {
    module: {
      rules: [
        {
          test: /\.pdf$/i,
          use: ['file-loader'],
        },
      ],
    },
  });
});

I've actually resolved it by splitting the content from one shared into multiple shared libraries.

@jaysoo
Copy link
Member

jaysoo commented Mar 28, 2023

Interesting, if you have a reproduction I can take a look. Otherwise I'll see if I can reproduce it locally.

@github-actions
Copy link

This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs.
If we missed this issue please reply to keep it active.
Thanks for being a part of the Nx community! 🙏

@github-actions
Copy link

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 27, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
blocked: repro needed outdated scope: testing tools Issues related to Cypress / Jest / Playwright / Vitest support in Nx stale type: bug
Projects
None yet
Development

No branches or pull requests

4 participants