Help me solve the problem please. A hook was written in the application when using next js, codemirror, cm6-graphql. And to solve dynamic import, the request is made in the effect.
export const useCodemirrorHook = <ElementType extends Element>(
props: Props
): React.MutableRefObject<ElementType | null> => {
const ref = useRef<ElementType>(null);
const { onChange, value } = props;
const [editorView, setEditorView] = useState<EditorView | null>(null);
useEffect(() => {
const { EditorView } = require("@codemirror/view");
const { EditorState } = require("@codemirror/state");
const { lineNumbers } = require("@codemirror/view");
const { history } = require("@codemirror/commands");
const {
autocompletion,
closeBrackets,
} = require("@codemirror/autocomplete");
const {
bracketMatching,
syntaxHighlighting,
} = require("@codemirror/language");
const {
oneDarkHighlightStyle,
oneDark,
} = require("@codemirror/theme-one-dark");
** const { graphql } = require("cm6-graphql");**
const state = EditorState.create({
doc: value,
extensions: [
syntaxHighlighting(oneDarkHighlightStyle),
history(),
lineNumbers(),
bracketMatching(),
autocompletion(),
closeBrackets(),
myTheme,
oneDark,
**graphql(),**
but when running the tests an error occurs.
Jest encountered an unexpected token
Jest failed to parse a file. This happens e.g. when your code or its dependencies use non-standard JavaScript syntax, or when Jest is not configured to support such syntax.
Out of the box Jest supports Babel, which will be used to transform your files into valid JS based on your Babel configuration.
By default "node_modules" folder is ignored by transformers.
Here's what you can do:
• If you are trying to use ECMAScript Modules, see https://jestjs.io/docs/ecmascript-modules for how to enable it.
• If you are trying to use TypeScript, see https://jestjs.io/docs/getting-started#using-typescript
• To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
• If you need a custom transformation specify a "transform" option in your config.
• If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.
C:\Users\Acer\Desktop\GraphiQL\graphiql-app\node_modules\vscode-languageserver-types\lib\esm\main.js:6
export var DocumentUri;
^^^^^^
SyntaxError: Unexpected token 'export'
36 | oneDark,
37 | } = require("@codemirror/theme-one-dark");
> 38 | const { graphql } = require("cm6-graphql");
I want using cm6-graphql in useeffect for resolve bag of dynamic import in next js.