X
X
xDanbo2019-12-26 10:23:55
Node.js
xDanbo, 2019-12-26 10:23:55

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

How to fix the situation (honestly googled, did not find the answer)?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
X
xDanbo, 2019-12-26
@xDanbo

There are no errors when I run tests in Webstorm as root in ubuntu. Apparently, the problem is in the environment variables.

S
Sergey Suntsev, 2019-12-26
@GreyCrew

Dig towards babel test compilation.
Or use the older import syntax
const React = require('react')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question