package.json依赖问题? -“未捕获的ReferenceError:未定义反应”

我遇到了一个问题,即我的构建可以在master分支上正常运行,但是在子分支上却产生“未捕获ReferenceError:未定义react”错误。两个分支的package.json略有不同,但是我仍然不确定为什么该分支显示错误,因为React被列为两个分支的依赖项。

主分支:

{
  "name": "master-branch","version": "0.0.1","description": "master-branch","main": "lib/index.js","pre-commit": [
    "test"
  ],"peerDependencies": {
    "antd": "3.x","react": "16.x","react-dom": "16.x"
  },"scripts": {
    "build": "rm -rf lib && NODE_ENV=production webpack --progress --config webpack.config.js ","docs:clean": "rm -rf docs/dist","docs:deploy": "yarn docs && gh-pages -d docs/dist","docs": "esdoc && yarn test:coverage && node docs/post-doc","test": "NODE_ENV=test jest","test:coverage": "jest --coverage","test:watch": "jest --watch","watch": "watch-run -p 'src/**' yarn build","storybook": "start-storybook -p 6006","storybook:watch": "concurrently \"yarn watch\" \"yarn storybook\"","storybook:build": "build-storybook -c .storybook -o build-stories"
  },"babel": {
    "presets": [
      "es2015","stage-0","react"
    ],"plugins": [
      "transform-class-properties","transform-custom-element-classes","transform-es2015-classes","transform-export-extensions"
    ]
  },"jest": {
    "coverageDirectory": "docs/dist/coverage"
  },"dependencies": {
    "antd": "3.6.5","async": "^2.6.0","axios": "^0.19.0","chance": "^1.0.13","classnames": "^2.2.5","jquery": "^3.2.1","lodash": "^4.17.15","md5": "^2.2.1","react-jss": "^8.4.0","store": "^2.0.12"
  },"devDependencies": {
    "@storybook/addon-actions": "^5.2.5","@storybook/addon-links": "^5.2.5","@storybook/react": "^5.2.5","babel-cli": "^6.26.0","babel-core": "^6.26.3","babel-loader": "^7.1.4","babel-plugin-transform-class-properties": "^6.24.1","babel-plugin-transform-custom-element-classes": "^0.1.0","babel-plugin-transform-es2015-classes": "^6.24.1","babel-plugin-transform-export-extensions": "^6.22.0","babel-preset-es2015": "^6.24.1","babel-preset-react": "^6.24.1","babel-preset-stage-0": "^6.24.1","esdoc": "^1.0.3","esdoc-ecmascript-proposal-plugin": "^1.0.0","esdoc-react-plugin": "^1.0.1","esdoc-standard-plugin": "^1.0.0","gh-pages": "^1.0.0","jest": "^23.6.0","pre-commit": "^1.2.2","react": "^16.3.2","react-dom": "^16.3.2","react-test-renderer": "^16.0.0","url-loader": "^1.1.1","watch-run": "^1.2.5","webpack": "^3.8.1","webpack-cli": "^2.0.4"
  },"author": "","homepage": "","license": "MIT","repository": "","keywords": [
    "react-component"
  ]
}

子分支:

{
  "name": "sub-branch","description": "sub-branch","peerDependencies": {
    "antd": "3.6.5","classnames": "^2.2.6","prop-types": "^15.7.2","react": "16.8","react-dom": "^16.9.0","react-jss": "^8.6.1"
  },"scripts": {
    "build": "rm -rf lib && NODE_ENV=production webpack --mode production --progress --config webpack.config.js ","storybook:watch": "concurrently \"yarn watch\" \"yarn storybook\""
  },"dependencies": {
    "@storybook/addon-storysource": "^5.2.0","antd": "^3.23.3","axios": "^0.16.2","lodash": "^4.17.4","react-dom": "16.8","react-jss": "^8.6.1","devDependencies": {
    "@babel/cli": "^7.6.0","@babel/core": "^7.6.0","@babel/plugin-proposal-class-properties": "^7.5.5","@babel/plugin-proposal-export-default-from": "^7.5.2","@babel/plugin-syntax-export-extensions": "^7.0.0-beta.32","@babel/plugin-transform-classes": "^7.5.5","@babel/preset-env": "^7.6.0","@babel/preset-react": "^7.0.0","@storybook/addon-actions": "^5.2.0","@storybook/addon-notes": "^5.2.1","@storybook/react": "^5.2.0","babel-loader": "^8.0.6","flexbox-react": "^4.4.0","jest": "^24.9.0","react-popper-tooltip": "^2.8.3","react-test-renderer": "^16.9.0","react-textarea-autosize": "^7.1.0","simplebar-react": "^1.3.0-alpha.1","storybook-addon-react-docgen": "^1.2.18","webpack": "^4.40.2","webpack-cli": "^3.3.8"
  },"keywords": [
    "react-component"
  ]
}

zhourqdl 回答:package.json依赖问题? -“未捕获的ReferenceError:未定义反应”

主分支react上的

被定义为“ devDependency”,而子分支上的

被定义为“ dependency”。我相信子支行也应该定义为“ devDependency”

本文链接:https://www.f2er.com/3062491.html

大家都在问