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

Mount Component that uses React.lazy throws webpack error #14592

Closed
vtereshyn opened this issue Jan 15, 2021 · 3 comments
Closed

Mount Component that uses React.lazy throws webpack error #14592

vtereshyn opened this issue Jan 15, 2021 · 3 comments
Labels
npm: @cypress/webpack-preprocessor @cypress/webpack-preprocessor package issues stage: needs review The PR code is done & tested, needs review stale no activity on this issue for a long period

Comments

@vtereshyn
Copy link

vtereshyn commented Jan 15, 2021

Test file:

import { mount } from '@cypress/react';
...

describe('Test', function () {
  it('test test test', () => {
    mount(
      <Suspense fallback={<div>loading...</div>}>
        <MockedProvider mocks={[]}>
          <MemoryRouter>
            <TestComponent />
          </MemoryRouter>
        </MockedProvider>
      </Suspense>
    );
    expect(2 + 2).equal(4);
  });

This will work

TestComponent.tsx

const TestComponent: FunctionComponent = () => {
	...
	return <div>...content...</div>
}

This won't work

TestComponent.tsx

const TestComponent: FunctionComponent = () => {
	const Another = lazy(() => import('../../AnotherComponent'));
	...
	return <div>...content...</div>
}

even if this imported component is not in use.

Btw, I have Suspense

const webpackOptions = {
  resolve: {
    extensions: ['.js', '.ts', '.tsx'],
    modules: [resolve(__dirname, 'src'), 'node_modules']
  },
  mode: 'development',
  devtool: false,
  output: {
    filename: 'bundle.js',
    path: resolve(__dirname, 'dist'),
    publicPath: '/'
  },
  module: {
    rules: [
      {
        test: /\.(ts|tsx)$/,
        use: [
          {
            loader: 'babel-loader',
            options: {
              rootMode: 'upward'
            }
          }
        ],
        exclude: /node_modules/
      },
      {
        test: /\.css$/,
        use: ['style-loader', 'css-loader', 'postcss-loader']
      }
    ]
  }
};

Thanks!

@cya
Copy link

cya commented Jan 16, 2021

Please, let's close this ASAP, looks like PR is ready.
Thanks, @vtereshyn

@cypress-bot cypress-bot bot added the stage: needs review The PR code is done & tested, needs review label Jan 19, 2021
@jennifer-shehane jennifer-shehane added the npm: @cypress/webpack-preprocessor @cypress/webpack-preprocessor package issues label Jan 19, 2021
@cypress-bot cypress-bot bot added stage: work in progress stage: needs review The PR code is done & tested, needs review and removed stage: needs review The PR code is done & tested, needs review stage: work in progress labels Jan 19, 2021
@Wholteza
Copy link

I'm experiencing this exact issue.

For me this occur when i import a constant from a file that has a React.lazy import in it directly into my spec files.

is there any development on this?

@cypress-app-bot
Copy link
Collaborator

This issue has not had any activity in 180 days. Cypress evolves quickly and the reported behavior should be tested on the latest version of Cypress to verify the behavior is still occurring. It will be closed in 14 days if no updates are provided.

@cypress-app-bot cypress-app-bot added the stale no activity on this issue for a long period label May 17, 2023
@cypress-app-bot cypress-app-bot closed this as not planned Won't fix, can't repro, duplicate, stale May 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
npm: @cypress/webpack-preprocessor @cypress/webpack-preprocessor package issues stage: needs review The PR code is done & tested, needs review stale no activity on this issue for a long period
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants