Answer the question
In order to leave comments, you need to log in
React + running test in Node.js: why doesn't import work?
React app created with create-react-app, Node.js version 12.14.0 (originally machine was v8, tried v13 as well). When running the code of simple tests, an error occurs in the terminal:
import React from "react";
^^^^^^
SyntaxError: Cannot use import statement outside a module
Answer the question
In order to leave comments, you need to log in
There are no errors when I run tests in Webstorm as root in ubuntu. Apparently, the problem is in the environment variables.
Dig towards babel test compilation.
Or use the older import syntaxconst React = require('react')
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question