0

我是 .net 开发人员,我是 nodejs 环境中的新手

所以我把项目代码放在一个文件夹中,然后我使用

npm install 

然后我使用 npm build 和 npm start build 命令,但它在 npm start build 命令之后给出了该错误

has already been exported. Exported identifiers must be unique.

我搜索那个错误。我找到了那个解决方案。我认为错误是关于 babel/babylon

https://github.com/babel/babylon/releases/tag/v6.11.2

但我不明白那个解决方案。我应该将 https://github.com/babel/babylon/releases/tag/v6.11.2那个巴比伦文件下载到节点模块下吗?但是在我的节点模块文件夹中,这里没有巴比伦我的 package.json 如何将该项目安装到任何文件夹?只需复制文件和 npm install 就足够了?

{
  "name": "react-seed",
  "version": "0.0.13",
  "description": "Seed project for React apps using ES6 & webpack.",
  "repository": "https://github.com/badsyntax/react-seed",
  "config": {
    "buildDir": "./build",
    "buildDirTests": "./build_tests",
    "devHost": "0.0.0.0",
    "devPort": 8000,
    "remoteHost": "http://yazilimsozluk.com"
  },
  "scripts": {
    "build": "set NODE_ENV=production&& npm run webpack",
    "clean": "rimraf $npm_package_config_buildDir && mkdir $npm_package_config_buildDir",
    "env": "env",
    "lint": "eslint --ext .js --ext .jsx ./app ./webpack && echo No linting errors.",
    "prebuild": "npm run clean",
    "pretest": "npm install && npm run lint",
    "pretest-travis": "npm install && npm run lint",
    "start": "set NODE_ENV=development && node dev-server ./webpack/config",
    "test": "NODE_ENV=test karma start --single-run",
    "test-dev": "NODE_ENV=test karma start",
    "test-travis": "NODE_ENV=test karma start --single-run",
    "webpack": "webpack --colors --progress --config ./webpack/config"
  },
  "dependencies": {
    "classnames": "^2.1.1",
    "hammerjs": "^2.0.4",
    "immutable": "^3.7.6",
    "intl": "^1.0.0",
    "intl-locales-supported": "^1.0.0",
    "jquery": "^2.1.4",
    "lodash": "^4.9.0",
    "materialize-css": "^0.97.5",
    "ms-signalr-client": "^2.2.2",
    "normalize.css": "^4.0.0",
    "react": "^0.14.8",
    "react-dnd": "^2.1.4",
    "react-dnd-html5-backend": "^2.1.2",
    "react-dnd-html5-touch-backend": "^1.5.0",
    "react-dnd-touch-backend": "^0.2.7",
    "react-dom": "^0.14.8",
    "react-flexgrid": "^0.7.0",
    "react-intl": "^2.0.0-rc-1",
    "react-redux": "^4.4.1",
    "redux": "^3.3.1",
    "redux-thunk": "^2.0.1",
    "superagent": "^1.3.0"
  },
  "devDependencies": {
    "autoprefixer": "^6.3.4",
    "babel-core": "^6.7.4",
    "babel-eslint": "^6.0.0",
    "babel-loader": "^6.2.4",
    "babel-plugin-rewire": "^1.0.0-rc-1",
    "babel-plugin-transform-decorators": "^6.6.5",
    "babel-plugin-transform-decorators-legacy": "^1.3.4",
    "babel-polyfill": "^6.7.4",
    "babel-preset-es2015": "^6.6.0",
    "babel-preset-react": "^6.5.0",
    "babel-preset-stage-0": "^6.5.0",
    "babel-runtime": "^6.6.1",
    "chai": "^2.3.0",
    "compass-mixins": "^0.12.7",
    "css-loader": "^0.23.1",
    "eslint": "^2.5.1",
    "eslint-plugin-react": "^4.2.3",
    "expose-loader": "^0.7.0",
    "extract-text-webpack-plugin": "^1.0.1",
    "file-loader": "^0.8.1",
    "glob": "^7.0.3",
    "html-loader": "^0.4.3",
    "inline-environment-variables-webpack-plugin": "^1.1.0",
    "json-loader": "^0.5.1",
    "karma": "^0.12.31",
    "karma-chrome-launcher": "^0.1.12",
    "karma-cli": "0.0.4",
    "karma-mocha": "^0.1.10",
    "karma-mocha-reporter": "^1.0.2",
    "karma-phantomjs-launcher": "^0.1.4",
    "karma-sinon": "^1.0.4",
    "karma-source-map-support": "^1.0.0",
    "karma-sourcemap-loader": "^0.3.4",
    "karma-webpack": "^1.5.1",
    "mocha": "^2.2.4",
    "mocha-loader": "^0.7.1",
    "node-libs-browser": "^1.0.0",
    "node-sass": "^3.4.2",
    "postcss-loader": "^0.8.2",
    "react-hot-loader": "^1.2.7",
    "rimraf": "^2.3.3",
    "sass-loader": "^3.2.0",
    "sinon": "^1.14.1",
    "source-map-support": "^0.4.0",
    "style-loader": "^0.13.1",
    "template-html-loader": "0.0.3",
    "webpack": "^1.12.14",
    "webpack-dev-server": "^1.8.2"
  },
  "engines": {
    "node": ">=0.10.0"
  },
  "eslintConfig": {
    "env": {
      "browser": true,
      "node": true,
      "es6": true
    },
    "ecmaFeatures": {
      "modules": true,
      "jsx": true
    },
    "globals": {
      "describe": true,
      "it": true,
      "xit": true,
      "xdescribe": true,
      "beforeEach": true,
      "sinon": true
    },
    "plugins": [
      "react"
    ],
    "parser": "babel-eslint",
    "rules": {
      "strict": true,
      "indent": [
        2,
        2
      ],
      "quotes": [
        2,
        "single"
      ],
      "new-cap": 0,
      "no-unused-expressions": 0,
      "no-underscore-dangle": 0,
      "react/display-name": 0,
      "react/jsx-quotes": 1,
      "react/jsx-no-undef": 1,
      "react/jsx-sort-props": 1,
      "react/jsx-uses-react": 1,
      "react/jsx-uses-vars": 1,
      "react/no-did-mount-set-state": 1,
      "react/no-did-update-set-state": 1,
      "react/no-multi-comp": 1,
      "react/no-unknown-property": 1,
      "react/prop-types": 1,
      "react/react-in-jsx-scope": 1,
      "react/self-closing-comp": 1,
      "react/wrap-multilines": 1
    }
  }
}

已编辑

mockPlayer 函数中的 mockhelper.js 发生错误这里是文件代码

    import _ from 'lodash';

import * as stoneHelpers from 'utils/stoneTestHelpers';

import { StoneColor,
         SequenceType } from 'constants/AppConstants';

export function mockStone(color = StoneColor.RED, number = 1) {
  return {
    number: number,
    color: color
  };
}

export function mockOkeyStoneWithHelper(okeyStone, helper) {
  return _.extend({}, okeyStone, {
    isOkey: true,
    okeyHelper: helper
  });
}

export function mockStoneWithId(color = StoneColor.RED, number= 1, id) {
  return {
    id: id,
    color: color,
    number: number
  };
}

export function mockPlayer(id, name) {
  return {
    id: id,
    name: name
  };
}

export function mockTable() {
  return {
    players: [
      mockPlayer(1, 'mockPlayer1'),
      mockPlayer(2, 'mockPlayer2'),
      mockPlayer(3, 'mockPlayer3'),
      mockPlayer(4, 'mockPlayer4')
    ],
    scoreboard: []
  };
}

export function mockOpenStoneGroups(owner) {
  return {
    groups: [stoneHelpers.buildStoneGroupSequenceWithStones(
      SequenceType.RAINBOW,
      stoneHelpers.buildStoneRainbow(5, 0),
      owner),
     stoneHelpers.buildStoneGroupSequenceWithStones(
       SequenceType.SAME_COLOR,
       stoneHelpers.buildStoneSameColor(6, StoneColor.GREEN, 300, 4),
       owner)
    ]
  };
}

export function mockOpenStoneGroupsWithGroups(groups) {
  return {
    groups: groups
  };
}

export function mockOpenStoneGroupsForPairs(owner, count) {
  const groups = [];

  while (count-- > 0) {
    groups.push(stoneHelpers.buildStoneGroupPairsWithStones(
      stoneHelpers.buildStonePair(count, StoneColor.RED, count * 100),
      owner
    ));
  }

  return mockOpenStoneGroupsWithGroups(groups);
}

export function mockStartInfo(currentTurn = 0) {
  return {
    stones: _.flatten([
      stoneHelpers.buildStoneSameColor(1, StoneColor.RED, 0, 3),
      stoneHelpers.buildStoneRainbow(13, 300),
      stoneHelpers.buildFreeStoneGroup(400)
    ]),
    discardStones: [
      [stoneHelpers.buildStone(1, StoneColor.RED)],
      [stoneHelpers.buildStone(2, StoneColor.BLACK)],
      [stoneHelpers.buildStone(3, StoneColor.GREEN)],
      [stoneHelpers.buildStone(4, StoneColor.BLUE)]
    ],
    gosterge: stoneHelpers.buildStone(10, StoneColor.BLACK),
    currentTurn: currentTurn
  };
}

export function mockPlayer(id, name, optional) {
  return _.extend({
    id: id,
    name: name
  }, {}, optional);
}

export function mockPlayerFull(id, name) {
  return mockPlayer(id, name, {
    state: {
      turnPoints: 10,
      openPoints: 100,
      openedHands: 0,
      hasOpenedPairs: false
    },
    timeLeft: 10
  });
}

export function mockTable(p1 = mockPlayerFull(1, 'mockPlayer1'),
                          p2 = mockPlayerFull(2, 'mockPlayer2'),
                          p3 = mockPlayerFull(3, 'mockPlayer3'),
                          p4 = mockPlayerFull(4, 'mockPlayer4')) {
  var result = {
    players: [
      p1,
      p2,
      p3,
      p4
    ]
  };
  return result;
}

export function mockMatchStats(ranking, player,
                               score, xp, hands,
                               punish, chips) {
  return {
    player: player,
    stats: {
      ranking: ranking,
      score: score,
      gainedXP: xp,
      openedHands: hands,
      punishment: punish,
      gainedChips: chips
    }
  };
}

export function mockMatchResult(p1 = mockPlayerFull(1, 'mockPlayer'),
                                p2 = mockPlayerFull(2, 'mockPlayer2'),
                                p3 = mockPlayerFull(3, 'mockPlayer3'),
                                p4 = mockPlayerFull(4, 'mockPlayer4')) {
  return {
    rankings: [
      mockMatchStats(1, p1, 100, 50, 2, 1, 400),
      mockMatchStats(2, p2, 50, 25, 1, 1, 200),
      mockMatchStats(3, p3, 25, 10, 1, 0, -100),
      mockMatchStats(4, p4, 10, 10, 1, 3, -200)
    ]
  };
}

export function mockInitialStateGamePlay() {
  return {
    discardStones: [[], [], [], []],
    sequence: [],
    pairs: [],
    selectedStone: null
  };
}
4

1 回答 1

2

您发布的错误

已经导出了。导出的标识符必须是唯一的。

如果您还不知道出了什么问题,可能还不够清楚。把它分解

导出的标识符必须是唯一的。

是说一个文件只能导出一个具有特定名称的东西。在您的特定代码中,您同时拥有

export function mockTable(
    p1 = mockPlayerFull(1, 'mockPlayer1'),
    p2 = mockPlayerFull(2, 'mockPlayer2'),
    p3 = mockPlayerFull(3, 'mockPlayer3'),
    p4 = mockPlayerFull(4, 'mockPlayer4')
) {
    // ...
}

export function mockTable() {
  return {
    players: [
      mockPlayer(1, 'mockPlayer1'),
      mockPlayer(2, 'mockPlayer2'),
      mockPlayer(3, 'mockPlayer3'),
      mockPlayer(4, 'mockPlayer4')
    ],
    scoreboard: []
  };
}

这是没有意义的。您不能在同一个范围内拥有两个同名的函数。

于 2017-08-04T17:16:36.793 回答