SyntaxError: Cannot use import statement outside a module
flowck opened this issue · comments
Hello,
I've just ran into the following issue while attempting to test with Jest a component that uses react-use-wizard
:
Details:
.../node_modules/react-use-wizard/dist/react-use-wizard.mjs:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,jest){import { createContext, useContext, memo, useState, useRef, Children, useMemo, isValidElement, cloneElement, createElement } from 'react';
^^^^^^
SyntaxError: Cannot use import statement outside a module
Any advice on how to proceed from here?
I ended up solving the issue aforementioned with the following Jest config:
// jest.config.js
const config = {
moduleNameMapper: {
'react-use-wizard': '<rootDir>/node_modules/react-use-wizard/dist/react-use-wizard.cjs.production.min.js',
}
}
Thanks for letting this know. Can you provide which version of react-use-wizard
you are using?
Hi @devrnt, thanks for your reply.
I am using the version 2.2.3
, other parts of the stack are:
- Next.js 13.4.5
- Jest 29.6.1
Cheers,
Firmino