将多个预设传递给create-react app package.json

时间:2017-04-15 12:14:03

标签: javascript babel create-react-app

我有以下package.json配置(babel选项位于底部):

{
  "name": "react-tea-timer",
  "version": "0.2.0",
  "private": false,
  "devDependencies": {
    "autoprefixer": "6.7.2",
    "babel-core": "6.22.1",
    "babel-eslint": "7.1.1",
    "babel-jest": "18.0.0",
    "babel-loader": "6.2.10",
    "babel-preset-mobx": "^1.0.1",
    "babel-preset-react-app": "^2.2.0",
    "babel-runtime": "^6.20.0",
    "case-sensitive-paths-webpack-plugin": "1.1.4",
    "chalk": "1.1.3",
    "connect-history-api-fallback": "1.3.0",
    "cross-spawn": "4.0.2",
    "css-loader": "0.26.1",
    "detect-port": "1.1.0",
    "dotenv": "2.0.0",
    "enzyme": "^2.7.1",
    "eslint": "3.16.1",
    "eslint-config-react-app": "^0.6.2",
    "eslint-loader": "1.6.0",
    "eslint-plugin-flowtype": "2.21.0",
    "eslint-plugin-import": "2.0.1",
    "eslint-plugin-jsx-a11y": "4.0.0",
    "eslint-plugin-react": "6.4.1",
    "extract-text-webpack-plugin": "1.0.1",
    "file-loader": "0.10.0",
    "flow-bin": "^0.42.0",
    "fs-extra": "0.30.0",
    "html-webpack-plugin": "2.24.0",
    "http-proxy-middleware": "0.17.3",
    "jest": "^19.0.2",
    "json-loader": "0.5.4",
    "object-assign": "4.1.1",
    "postcss-loader": "1.2.2",
    "promise": "7.1.1",
    "react-addons-test-utils": "^15.4.2",
    "react-dev-utils": "^0.5.2",
    "sinon": "^2.1.0",
    "style-loader": "0.13.1",
    "url-loader": "0.5.7",
    "webpack": "1.14.0",
    "webpack-dev-server": "1.16.2",
    "webpack-manifest-plugin": "1.1.0",
    "whatwg-fetch": "2.0.2"
  },
  "dependencies": {
    "mobx": "^3.1.9",
    "mobx-react": "^4.1.8",
    "rc-slider": "^6.3.1",
    "react": "^15.4.2",
    "react-blur-image-loader": "^0.2.2",
    "react-dom": "^15.4.2",
    "react-router": "^3.0.2"
  },
  "scripts": {
    "start": "node scripts/start.js",
    "build": "node scripts/build.js",
    "test": "node scripts/test.js --env=jsdom",
    "predeploy": "npm run build",
    "deploy": "gh-pages -d build",
    "flow": "flow"
  },
  "jest": {
    "collectCoverageFrom": [
      "src/**/*.{js,jsx}"
    ],
    "setupFiles": [
      "<rootDir>/config/polyfills.js"
    ],
    "testPathIgnorePatterns": [
      "<rootDir>[/\\\\](build|docs|node_modules|scripts)[/\\\\]"
    ],
    "testEnvironment": "node",
    "testURL": "http://localhost",
    "transform": {
      "^.+\\.(js|jsx)$": "<rootDir>/node_modules/babel-jest",
      "^.+\\.css$": "<rootDir>/config/jest/cssTransform.js",
      "^(?!.*\\.(js|jsx|css|json)$)": "<rootDir>/config/jest/fileTransform.js"
    },
    "transformIgnorePatterns": [
      "[/\\\\]node_modules[/\\\\].+\\.(js|jsx)$"
    ],
    "moduleNameMapper": {
      "^react-native$": "react-native-web"
    }
  },
  "babel": {
    "presets": [
      "react-app",
      "mobx"
    ]
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "homepage": "https://shooshte.github.io/teaTimer/"
}

现在根据babel docs这是传递多个预设的正确方法,但是在运行npm run start时我仍然收到以下错误:

  

./src/Stores/timerStore.js中的错误模块构建失败:   ReferenceError:[BABEL]   /Users/shooshte/PersonalProjects/teaTimer/src/Stores/timerStore.js:   未知选项:   /Users/shooshte/PersonalProjects/teaTimer/node_modules/mobx/lib/mobx.js.extras。   有关详细信息,请查看http://babeljs.io/docs/usage/options/   关于选项。

     

此错误的常见原因是存在配置   options对象没有相应的预设名称。例如:

     

无效:{ presets: [{option: value}] }有效:{ presets: [['presetName', {option: value}]] }

     

有关预设配置的更多详细信息,请参阅   http://babeljs.io/docs/plugins/#pluginpresets-options。 (而   处理预设:   &#34; /Users/shooshte/PersonalProjects/teaTimer/node_modules/mobx/lib/mobx.js")       在Array.map(native)@ ./src/index.js 15:18-48

0 个答案:

没有答案