Unable to use Jest: SyntaxError: Unexpected identifier at Runtime.createScriptFromCode

Unable to use Jest: SyntaxError: Unexpected identifier at Runtime.createScriptFromCode

我刚刚用 npm 安装了 Jest,现在我正在尝试 运行 一些测试。结果我无法这样做,因为我收到以下错误:

● Test suite failed to run

C:\Users\aleja\Documents\FINAL PAW POSTA\paw-2018b-10\frontend\src\tests\PublicationService.test.js:3
import PublicationService from '../services/PublicationService'; // import * as StatusCode from '../util/StatusCode'
       ^^^^^^^^^^^^^^^^^^

SyntaxError: Unexpected identifier

  at Runtime.createScriptFromCode (node_modules/jest-runtime/build/index.js:1059:14)

这是我的 package.json。我已经阅读了有关 babel.rc 文件和内容的其他问题,但我什至没有这些文件。

{
  "name": "frontend",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@babel/preset-react": "^7.7.4",
    "@material-ui/core": "^4.8.2",
    "@material-ui/icons": "^4.5.0",
    "@material/react-linear-progress": "^0.15.0",
    "axios": "^0.19.0",
    "axios-mock-adapter": "^1.17.0",
    "babel-jest": "^25.1.0",
    "bootstrap": "^4.4.1",
    "crypto-js": "^3.1.9-1",
    "enzyme": "^3.11.0",
    "formik": "^1.5.8",
    "i18next": "^17.3.1",
    "i18next-browser-languagedetector": "^3.1.1",
    "i18next-xhr-backend": "^3.2.2",
    "jest": "^25.1.0",
    "mutex-promise": "^0.1.0",
    "query-string": "^6.9.0",
    "react": "^16.12.0",
    "react-bootstrap": "^1.0.0-beta.16",
    "react-bootstrap-switch": "^15.5.3",
    "react-content-loader": "^4.3.4",
    "react-dom": "^16.12.0",
    "react-form-validator-core": "^0.6.4",
    "react-geocode": "^0.2.1",
    "react-google-maps": "^9.4.5",
    "react-i18next": "^10.13.2",
    "react-images-upload": "^1.2.7",
    "react-images-viewer": "^1.6.2",
    "react-material-ui-form-validator": "^2.0.9",
    "react-notifications-component": "^2.2.4",
    "react-paginate": "^6.3.2",
    "react-router-dom": "^5.1.2",
    "react-scripts": "^3.3.0",
    "react-spring": "^8.0.27",
    "react-toast-notifications": "^2.4.0",
    "redux": "^4.0.5",
    "toasted-notes": "^3.2.0",
    "webfontloader": "^1.6.28",
    "yup": "^0.27.0"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "jest",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },
  "devDependencies": {
    "@babel/cli": "^7.1.2",
    "@babel/core": "^7.1.2",
    "@babel/preset-env": "^7.1.0",
    "@babel/preset-react": "^7.0.0",
    "@testing-library/jest-dom": "^5.0.2",
    "@testing-library/react": "^9.4.0",
    "babel-plugin-transform-es2015-modules-amd": "^6.24.1",
    "grunt": "^1.0.4",
    "grunt-babel": "^8.0.0",
    "grunt-sass": "^3.1.0",
    "grunt-war": "^0.5.1",
    "node-sass": "^4.13.1",
    "react-test-renderer": "^16.12.0",
    "reactotron-react-js": "^3.3.7",
    "sass": "^1.24.0"
  },

  "jest": {
    "modulePaths": [
      "node_modules"
    ],
    "moduleFileExtensions": [
      "js",
      "jsx"
    ],
    "moduleDirectories": [
      "node_modules"
    ]
  },
  "homepage": "http://mypage.com/",
  "proxy": "http://localhost:8080"
}

我已经添加了一些 babel 依赖项,但问题仍然没有得到解决。

我还在 package.json 我阅读的另一个问题中添加了 "Jest" 部分。仍然没有运气。

好吧,好像我必须在根目录中创建一个 babel.config.js 文件,因为它说 here

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