Reactjs 开玩笑
我正在一个项目上运行Reactjs 开玩笑,reactjs,typescript,jestjs,Reactjs,Typescript,Jestjs,我正在一个项目上运行纱线测试,我得到以下错误: ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){export { default as a11yDark } from './a11y-dark';
纱线测试
,我得到以下错误:
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){export { default as a11yDark } from './a11y-dark';
^^^^^^
SyntaxError: Unexpected token 'export'
1 | import React, { PureComponent } from "react";
2 | import SyntaxHighlighter from "react-syntax-highlighter";
> 3 | import { idea } from "react-syntax-highlighter/dist/esm/styles/hljs";
我正在使用ts jest
,我的jest.config.js
设置为:
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
};
还有我的package.json
:
{
"name": "client",
"version": "0.1.0",
"private": true,
"engines": {
"node": "14.15.0"
},
"dependencies": {
"@fortawesome/fontawesome-svg-core": "^1.2.32",
"@fortawesome/free-brands-svg-icons": "^5.8.1",
"@fortawesome/free-solid-svg-icons": "^5.15.1",
"@fortawesome/react-fontawesome": "^0.1.4",
"@types/jest": "26.0.15",
"@types/node": "14.14.7",
"@types/node-fetch": "^2.5.7",
"@types/react": "17.0.0",
"@types/react-dom": "17.0.0",
"@types/react-router-dom": "5.1.6",
"@types/react-syntax-highlighter": "13.5.0",
"bootstrap": "^4.5.3",
"hydrogen": "0.2.0",
"node-fetch": "^2.6.1",
"react": "17.0.1",
"react-app-polyfill": "2.0.0",
"react-dom": "17.0.1",
"react-ga": "3.3.0",
"react-markdown": "5.0.3",
"react-router-dom": "5.2.0",
"react-scripts": "4.0.1",
"react-syntax-highlighter": "15.3.1",
"tslint": "^6.1.3",
"typescript": "4.1.2",
"url-search-params-polyfill": "8.1.0"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "tsc --noEmit -p . && react-scripts test --all",
"eject": "react-scripts eject",
"lint": "tslint --project ."
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": [
">0.2%",
"not dead",
"not ie <= 11",
"not op_mini all"
],
"devDependencies": {
"@types/enzyme": "^3.10.8",
"@types/enzyme-adapter-react-16": "^1.0.6",
"enzyme": "3.11.0",
"enzyme-adapter-react-16": "^1.15.5"
}
}
{
“名称”:“客户”,
“版本”:“0.1.0”,
“私人”:没错,
“发动机”:{
“节点”:“14.15.0”
},
“依赖项”:{
“@fortawesome/fontawesome svg核心”:“^1.2.32”,
“@fortawesome/free brands svg图标”:“^5.8.1”,
“@fortawesome/free实心svg图标”:“^5.15.1”,
“@fortawesome/react-fontawesome”:“^0.1.4”,
“@types/jest”:“26.0.15”,
“@types/node”:“14.14.7”,
“@types/node fetch”:“^2.5.7”,
“@types/react”:“17.0.0”,
“@types/react-dom”:“17.0.0”,
“@types/react路由器dom”:“5.1.6”,
“@types/react语法高亮显示”:“13.5.0”,
“引导”:“^4.5.3”,
“氢”:“0.2.0”,
“节点提取”:“^2.6.1”,
“反应”:“17.0.1”,
“react应用程序polyfill”:“2.0.0”,
“react dom”:“17.0.1”,
“react ga”:“3.3.0”,
“反应降价”:“5.0.3”,
“react路由器dom”:“5.2.0”,
“反应脚本”:“4.0.1”,
“react语法荧光灯”:“15.3.1”,
“tslint”:“^6.1.3”,
“类型脚本”:“4.1.2”,
“url搜索参数polyfill”:“8.1.0”
},
“脚本”:{
“开始”:“反应脚本开始”,
“构建”:“反应脚本构建”,
“测试”:“tsc--noEmit-p.&react脚本测试--all”,
“弹出”:“反应脚本弹出”,
“lint”:“tslint——项目。”
},
“eslintConfig”:{
“扩展”:“反应应用程序”
},
“浏览者”:[
">0.2%",
“没有死”,
“不是ie答案是将模块导入为commonjs
,而不是esm
,如下所示:
import idea from "react-syntax-highlighter/dist/cjs/styles/hljs/idea";
import idea from "react-syntax-highlighter/dist/cjs/styles/hljs/idea";