修复错误的babel依赖关系后,Jest遇到了意外令牌

时间:2018-08-24 14:57:48

标签: reactjs dependencies jestjs babel

这是我的package.json,我有“ babel-core”:“ 7.0.0-bridge.0”,但仍然收到此错误。安装新的npm后,我收到有关Jest的新错误,遇到意外令牌。 / p>

  "dependencies": {
    "axios": "^0.18.0",
    "babel-eslint": "^8.2.2",
    "babel-plugin-transform-object-rest-spread": "^6.26.0",
    "classnames": "2.2.5",
    "core-js": "2.5.5",
    "enzyme-to-json": "^3.3.0",
    "form-data": "^2.3.2",
    "jest": "^23.4.1",
    "json-parse-better-errors": "^1.0.2",
    "yarn": "^1.7.0"
  },
  "devDependencies": {
    "@babel/core": "7.0.0-beta.46",
    "@babel/plugin-proposal-class-properties": "^7.0.0-beta.42",
    "@babel/preset-env": "7.0.0-beta.46",
    "@babel/preset-react": "7.0.0-beta.46",
    "@babel/register": "7.0.0-beta.46",
    "@babel/runtime": "7.0.0-beta.42",
    "babel-core": "7.0.0-bridge.0",
    "babel-loader": "^7.0.0"
  }

我现在有一个新错误

Jest encountered an unexpected token

    This usually means that you are trying to import a file which Jest cannot parse, e.g. it's not plain JavaScript.

    By default, if Jest sees a Babel config, it will use that to transform your files, ignoring "node_modules".

    Here's what you can do:
     • To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.

     • If you need a custom transformation specify a "transform" option in your config.
     • If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" con
fig option.

{"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import Enzyme from 'enzyme';

这是我的文件

import Enzyme from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
Enzyme.configure({ adapter: new Adapter() });

这是我的babelrc文件:

{
  "presets": [
    [
      "@babel/preset-env",
      {
        "modules": false
      }
    ],
    "@babel/react"
  ],
  "plugins": [
    "react-hot-loader/babel",
    "@babel/plugin-proposal-class-properties",
    "transform-class-properties"
  ]
}

0 个答案:

没有答案