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

TypeError: Chalk is not a constructor #243

Open
EHadoux opened this issue Oct 24, 2024 · 6 comments
Open

TypeError: Chalk is not a constructor #243

EHadoux opened this issue Oct 24, 2024 · 6 comments

Comments

@EHadoux
Copy link

EHadoux commented Oct 24, 2024

Looks like this line is problematic:

const chalk = new Chalk({ level: 3 });

aws-sdk-client-mock: 4.1.0
aws-sdk-client-mock-jest: 4.1.0

Replacing with:

import { Instance } from 'chalk';

const chalk = new Instance({ level: 3 });

seems to fix it. I can open a PR if you're happy with this change 👍

@m-radzikowski
Copy link
Owner

Hey, can you provide a repro details when you encounter this issue?

@slcp
Copy link

slcp commented Oct 25, 2024

I saw the same behaviour and I have resolved this issue by installing chalk 5.3.0 (just latest at the time) as a dev dependency of my project (not ideal).

I can see that chalk is installed in the jest matcher package as a devDependency, is that intentional? It isn't being declared as a dependency of the installed package which maybe it should be? And if there is another version of chalk around (I think that was where my issue was) unexpected behaviour like this issue describes might be seen.

@travi
Copy link

travi commented Oct 25, 2024

i just ran into this issue as well and agree that making chalk a prod dependency instead of a dev-dependency is the correct fix if the use of chalk is needed there

@EHadoux
Copy link
Author

EHadoux commented Oct 25, 2024

Yeah sorry, my initial post could have been better. The solution is indeed to have the latest version of chalk and not to change the code to comply with a previous version as suggested in my initial post.

@cawofeso
Copy link

cawofeso commented Nov 1, 2024

I am also facing this problem as well so created a pr to move chalk as a dependency instead of a dev dependency
@m-radzikowski if you could take a look that would be great

@alexbaileyuk
Copy link

Same issue here today. For now have installed chalk 5.3.0 as a dev dependency in my project. Unfortunately that did not solve the problem for me.

import 'aws-sdk-client-mock-jest/vitest';
import { mockClient } from 'aws-sdk-client-mock';
import { beforeEach, describe, expect, test } from 'vitest';
import { DynamoDBDocumentClient, PutCommand, QueryCommand } from '@aws-sdk/lib-dynamodb';
import { recordCodeSentHistory } from '../../src/login-codes/code-history';

describe('tests', () => {
  const ddbMock = mockClient(DynamoDBDocumentClient);

  beforeEach(() => {
    ddbMock.reset();
  });

  test('it should record login code history in dynamodb', async () => {
    ddbMock.on(PutCommand).resolves({});

    await recordCodeSentHistory('dynamo_table', '[email protected]', 2);

    expect(true).toBeTruthy();
  });
});
 FAIL  functions/cognito-create-auth-challenge/test/login-codes/code-history.test.ts [ functions/cognito-create-auth-challenge/test/login-codes/code-history.test.ts ]
TypeError: Chalk is not a constructor
 ❯ node_modules/aws-sdk-client-mock-jest/src/vitest.ts:23:5
 ❯ functions/cognito-create-auth-challenge/test/login-codes/code-history.test.ts:1:1
      1| import 'aws-sdk-client-mock-jest/vitest';
       | ^
      2| import { mockClient } from 'aws-sdk-client-mock';
      3| import { beforeEach, describe, expect, test } from 'vitest';

I've tried importing in different orders and re-installing node_modules with no success.

Would be great to get this PR merged to remove the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants