devrnt / react-use-wizard

🧙 A React wizard (stepper) builder without the hassle, powered by hooks.

Home Page:https://devrnt.github.io/react-use-wizard/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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?

jest_config_js_—_web-ng

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

thanks @flowck your code worked. I'm also using v2.2.3 and was having the SyntaxError: Cannot use import statement outside a module error in jest