jtest: SyntaxError: Cannot use import statement outside a module

简介: jtest: SyntaxError: Cannot use import statement outside a module

使用jtest报错如下

jtest: SyntaxError: Cannot use import statement outside a module

原因是jtest 不支持es6语法,需要使用 Babel

npm install --save-dev babel-jest @babel/core @babel/preset-env

package.json

{
  "type": "module"
}

babel.config.cjs

module.exports = {
  presets: [['@babel/preset-env', {targets: {node: 'current'}}]],
};


相关文章
Failed to execute script ‘xxx‘ due to unhandled exception:No module named ‘ctypes‘
Failed to execute script ‘xxx‘ due to unhandled exception:No module named ‘ctypes‘
438 0
|
5月前
|
Python
【Python】已解决:AttributeError: module ‘sys’ has no attribute ‘setdefaultencoding’
【Python】已解决:AttributeError: module ‘sys’ has no attribute ‘setdefaultencoding’
228 0
|
3月前
|
JavaScript Python
7-4|execjs._exceptions.ProgramError: Error: Cannot find module 'jsdom'
7-4|execjs._exceptions.ProgramError: Error: Cannot find module 'jsdom'
|
5月前
|
开发者 Python
【Python】已解决:FutureWarning: The default value of regex will change from True to False in a future ver
【Python】已解决:FutureWarning: The default value of regex will change from True to False in a future ver
123 1
|
5月前
|
前端开发
Error in created hook: “TypeError: _test.default is not a function
Error in created hook: “TypeError: _test.default is not a function
|
5月前
|
Python
【Python】已解决:(from docx import Document导包报错)ModuleNotFoundError: No module named ‘exceptions’
【Python】已解决:(from docx import Document导包报错)ModuleNotFoundError: No module named ‘exceptions’
310 0
|
7月前
AttributeError: module 'torchaudio' has no attribute 'io'问题解决
【5月更文挑战第27天】AttributeError: module 'torchaudio' has no attribute 'io'问题解决
60 2
|
6月前
|
Python
【已解决】ModuleNotFoundError: No module named ‘DBUtils‘,from DBUtils.PooledDB import PooledDB,
【已解决】ModuleNotFoundError: No module named ‘DBUtils‘,from DBUtils.PooledDB import PooledDB,
270 0
|
6月前
|
关系型数据库 MySQL Linux
FATAL ERROR: Could not find my_print_defaults
FATAL ERROR: Could not find my_print_defaults
170 0
|
数据库
解决numpy.core._exceptions.UFuncTypeError: ufunc ‘add‘ did not contain a loop with signature matching
解决numpy.core._exceptions.UFuncTypeError: ufunc ‘add‘ did not contain a loop with signature matching
1147 0
解决numpy.core._exceptions.UFuncTypeError: ufunc ‘add‘ did not contain a loop with signature matching