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'}}]],
};


相关文章
|
11月前
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‘
380 0
|
3月前
|
Python
【Python】已解决:AttributeError: module ‘sys’ has no attribute ‘setdefaultencoding’
【Python】已解决:AttributeError: module ‘sys’ has no attribute ‘setdefaultencoding’
83 0
|
7天前
|
JavaScript Python
7-4|execjs._exceptions.ProgramError: Error: Cannot find module 'jsdom'
7-4|execjs._exceptions.ProgramError: Error: Cannot find module 'jsdom'
|
3月前
|
Python
【Python】已解决:(from docx import Document导包报错)ModuleNotFoundError: No module named ‘exceptions’
【Python】已解决:(from docx import Document导包报错)ModuleNotFoundError: No module named ‘exceptions’
135 0
|
5月前
AttributeError: module 'torchaudio' has no attribute 'io'问题解决
【5月更文挑战第27天】AttributeError: module 'torchaudio' has no attribute 'io'问题解决
28 2
|
4月前
|
Python
【已解决】ModuleNotFoundError: No module named ‘DBUtils‘,from DBUtils.PooledDB import PooledDB,
【已解决】ModuleNotFoundError: No module named ‘DBUtils‘,from DBUtils.PooledDB import PooledDB,
144 0
|
10月前
|
Kubernetes Python 微服务
Python3异常-AttributeError: module 'sys' has no attribute 'setdefaultencoding
Python3异常-AttributeError: module 'sys' has no attribute 'setdefaultencoding
80 0
|
11月前
|
JavaScript
vue运行报错:SyntaxError: Cannot use import statement outside a module
vue运行报错:SyntaxError: Cannot use import statement outside a module
176 0
|
11月前
ModuleNotFoundError: No module named ‘exceptions‘
ModuleNotFoundError: No module named ‘exceptions‘
【已解决!】ImportError: cannot import name ‘ProjectModelSerializer‘ from partially initialized module ‘pr
【已解决!】ImportError: cannot import name ‘ProjectModelSerializer‘ from partially initialized module ‘pr