The issue
Recently, I migrated from CRA ‘jest’ to Vitest, but I’m getting the following error:
require() of ES Module <path>rushcommontempnode_modules.pnpm@[email protected]_rnode_modules@azuremsal-reactdistindex.js from <path>rushpackagesauthdistindex.js not supported.
Instead change the require of <path>rushcommontempnode_modules.pnpm@[email protected]_rnode_modules@azuremsal-reactdistindex.js in <path>rushpackagesauthdistindex.js to a dynamic import() which is available in all CommonJS modules.
The package azure/msal-react is being used by a third-party package, meaning I import package X, and package X imports the @azure/msal-react library,
I have my vite.config.ts file configured with the test attributes as follows:
export default defineConfig(async ({ mode }) => {
//...code
return {
//...code
test: {
environment: 'jsdom',
globals: true,
setupFiles: ['./src/setupTests.ts'],
}
}
I’ve already tried using an alias and server.deps.inline: [‘@azure/msal-react’], but nothing worked.
I configured Jest in another environment, and it can be ‘bypassed’ by mocking with jest.mock("@azure/msal-react");
or by adding the package to moduleNameMapper
/transformIgnorePatterns
.
However, mocking with vi.mock("@azure/msal-react")
; doesn’t work, and
@azure/msal-react
don’t have a .mjs
file to set an alias :’)
Does anyone have any idea how to resolve this?
Halersson Paris is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.