create-react-app执行npm test报错

发布于 2022-09-11 19:47:14 字数 3417 浏览 20 评论 0

报错信息如下

 FAIL  src/App.test.js
  ● Test suite failed to run

    ReferenceError: [BABEL] C:\Users\htbst\Desktop\woyin-h5\src\App.test.js: Unknown option: base.configFile. Check out http://babeljs.io/docs/usage/options/ for more information about options.

    A common cause of this error is the presence of a configuration options object without the corresponding preset name. Example:

    Invalid:
      `{ presets: [{option: value}] }`
    Valid:
      `{ presets: [['presetName', {option: value}]] }`

    For more detailed information on preset configuration, please see https://babeljs.io/docs/en/plugins#pluginpresets-options.

      at Logger.error (node_modules/_babel-core@6.26.3@babel-core/lib/transformation/file/logger.js:41:11)
      at OptionManager.mergeOptions (node_modules/_babel-core@6.26.3@babel-core/lib/transformation/file/options/option-manager.js:226:20)
      at OptionManager.init (node_modules/_babel-core@6.26.3@babel-core/lib/transformation/file/options/option-manager.js:368:12)
      at File.initOptions (node_modules/_babel-core@6.26.3@babel-core/lib/transformation/file/index.js:212:65)
      at new File (node_modules/_babel-core@6.26.3@babel-core/lib/transformation/file/index.js:135:24)
      at Pipeline.transform (node_modules/_babel-core@6.26.3@babel-core/lib/transformation/pipeline.js:46:16)

package.json

{
  "name": "react_demo",
  "version": "0.1.0",
  "private": true,
  "homepage": "/",
  "dependencies": {
    "@babel/polyfill": "^7.4.3",
    "amfe-flexible": "^2.2.1",
    "axios": "^0.18.0",
    "classnames": "^2.2.6",
    "dayjs": "^1.8.12",
    "jwt-decode": "^2.2.0",
    "md5": "^2.2.1",
    "moment": "^2.24.0",
    "qs": "^6.7.0",
    "react": "^16.6.3",
    "react-dom": "^16.6.3",
    "react-helmet": "^5.2.0",
    "react-loadable": "^5.5.0",
    "react-motion": "^0.5.2",
    "react-redux": "^6.0.0",
    "react-refetch": "^2.0.3",
    "react-router-dom": "^4.3.1",
    "react-scripts": "2.1.1",
    "react-transition-group": "^2.5.2",
    "recompose": "^0.30.0",
    "redux": "^4.0.1",
    "redux-form-utils": "^1.1.2",
    "redux-thunk": "^2.3.0",
    "styled-components": "^4.1.3",
    "uuid": "^3.3.2",
    "vconsole": "^3.3.0",
    "weui": "^1.1.3",
    "weui.js": "^1.1.4"
  },
  "scripts": {
    "start": "react-app-rewired start",
    "build": "react-app-rewired build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": [
    ">0.2%",
    "not dead",
    "not ie <= 11",
    "not op_mini all"
  ],
  "devDependencies": {
    "babel-core": "^6.26.3",
    "http-proxy-middleware": "^0.19.1",
    "mockjs": "^1.0.1-beta3",
    "pretender": "^2.1.1",
    "react-app-rewired": "^2.1.1",
    "webpack-bundle-analyzer": "^3.3.2"
  }
}

config-overrides.js

const path = require('path')
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin

function resolve (dir) {
  return path.join(__dirname, dir)
}

module.exports = function override(config, env) {
  config.resolve.alias['@'] = resolve('src')
  if(env === 'production') {
    config.externals = {
      'react': 'React',
      'react-dom': 'ReactDOM'
    }
    // config.plugins.push(new BundleAnalyzerPlugin())
  }

  // do stuff with the webpack config...
  return config
};

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

雨轻弹 2022-09-18 19:47:14

根据 https://github.com/facebook/c...

应该是 babel-core 的版本问题,使用 "babel-core": "7.0.0-bridge.0" 代替 "babel-core": "^6.26.3" 应该可以解决。

赢得她心 2022-09-18 19:47:14

script脚本命令除了start可以直接npm start , 其他的都是npm run * 这样的命令,比如 npm run test

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文