V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
hsuyeung
V2EX  ›  前端开发

React 项目运行 `yarn` 命令安装依赖的时候收到警告 `warning Workspaces can only be enabled in private projects.` 如何解决

  •  
  •   hsuyeung · 2022-05-09 22:59:16 +08:00 · 1987 次点击
    这是一个创建于 934 天前的主题,其中的信息可能已经有所发展或是发生改变。

    google 搜了一圈儿,有说是 package.json 需要设置 "private": true,,但是我用 CRA 常见的 React 项目已经自动配置了这个了,没有解决问题。

    第 1 条附言  ·  2022-05-10 11:08:56 +08:00
    一个一个依赖删除然后运行 yarn 命令,最后确定是 npm 依赖的问题,只要安装 npm 就会有这个警告,解决办法的话需要 npm 里把 Workspaces 删除,参考 https://github.com/webpack/webpack-cli/pull/481/commits/a1a796de57a7ee2086b8352f4bb60caf50e118f0
    3 条回复    2022-05-10 09:15:26 +08:00
    hsuyeung
        1
    hsuyeung  
    OP
       2022-05-09 23:01:09 +08:00
    完整的 package.json:
    ```json
    {
    "name": "XXX",
    "version": "0.1.0",
    "private": true,
    "dependencies": {
    "@babel/core": "^7.16.0",
    "@babel/plugin-syntax-flow": "^7.14.5",
    "@babel/plugin-transform-react-jsx": "^7.14.9",
    "@emotion/react": "^11.9.0",
    "@emotion/styled": "^11.8.1",
    "@pmmmwh/react-refresh-webpack-plugin": "^0.5.3",
    "@svgr/webpack": "^5.5.0",
    "@testing-library/dom": ">=7.21.4",
    "@testing-library/jest-dom": "^5.16.4",
    "@testing-library/react": "^13.1.1",
    "@testing-library/user-event": "^14.1.1",
    "@types/jest": "^27.4.1",
    "@types/node": "^17.0.25",
    "@types/react": "^18.0.5",
    "@types/react-dom": "^18.0.1",
    "@typescript-eslint/eslint-plugin": "^5.20.0",
    "@typescript-eslint/parser": "^5.20.0",
    "babel-jest": "^27.4.2",
    "babel-loader": "^8.2.3",
    "babel-plugin-named-asset-import": "^0.3.8",
    "babel-preset-react-app": "^10.0.1",
    "bfj": "^7.0.2",
    "browserslist": "^4.18.1",
    "camelcase": "^6.2.1",
    "case-sensitive-paths-webpack-plugin": "^2.4.0",
    "css-loader": "^6.5.1",
    "css-minimizer-webpack-plugin": "^3.2.0",
    "dotenv": "^10.0.0",
    "dotenv-expand": "^5.1.0",
    "eslint": "^8.3.0",
    "eslint-config-alloy": "^4.5.1",
    "eslint-config-react-app": "^7.0.1",
    "eslint-plugin-prettier": "^4.0.0",
    "eslint-plugin-react": "^7.29.4",
    "eslint-plugin-react-hooks": "^4.5.0",
    "eslint-webpack-plugin": "^3.1.1",
    "file-loader": "^6.2.0",
    "fs-extra": "^10.0.0",
    "html-webpack-plugin": "^5.5.0",
    "identity-obj-proxy": "^3.0.0",
    "jest": "^27.4.3",
    "jest-resolve": "^27.4.2",
    "jest-watch-typeahead": "^1.0.0",
    "less": "^4.1.2",
    "less-loader": "^10.2.0",
    "mini-css-extract-plugin": "^2.4.5",
    "npm": "^8.8.0",
    "postcss": "^8.4.4",
    "postcss-flexbugs-fixes": "^5.0.2",
    "postcss-loader": "^6.2.1",
    "postcss-normalize": "^10.0.1",
    "postcss-preset-env": "^7.0.1",
    "prettier": "^2.6.2",
    "prompts": "^2.4.2",
    "react": "^18.0.0",
    "react-app-polyfill": "^3.0.0",
    "react-dev-utils": "^12.0.1",
    "react-dom": "^18.0.0",
    "react-refresh": "^0.11.0",
    "react-router-dom": "6",
    "resolve": "^1.20.0",
    "resolve-url-loader": "^4.0.0",
    "sass-loader": "^12.3.0",
    "semver": "^7.3.5",
    "source-map-loader": "^3.0.0",
    "style-loader": "^3.3.1",
    "tailwindcss": "^3.0.2",
    "terser-webpack-plugin": "^5.2.5",
    "typescript": "^4.6.3",
    "web-vitals": "^2.1.4",
    "webpack": "^5.64.4",
    "webpack-dev-server": "^4.7.3",
    "webpack-manifest-plugin": "^4.0.2",
    "workbox-webpack-plugin": "^6.4.1"
    },
    "scripts": {
    "start": "node scripts/start.js",
    "build": "node scripts/build.js",
    "test": "node scripts/test.js"
    },
    "eslintConfig": {
    "extends": [
    "react-app",
    "react-app/jest"
    ]
    },
    "browserslist": {
    "production": [
    ">0.2%",
    "not dead",
    "not op_mini all"
    ],
    "development": [
    "last 1 chrome version",
    "last 1 firefox version",
    "last 1 safari version"
    ]
    },
    "description": "XXXXXX",
    "main": "index.tsx",
    "repository": "XXXXXXXX",
    "author": "XXXX",
    "license": "XXX",
    "jest": {
    "roots": [
    "<rootDir>/src"
    ],
    "collectCoverageFrom": [
    "src/**/*.{js,jsx,ts,tsx}",
    "!src/**/*.d.ts"
    ],
    "setupFiles": [
    "react-app-polyfill/jsdom"
    ],
    "setupFilesAfterEnv": [],
    "testMatch": [
    "<rootDir>/src/**/__tests__/**/*.{js,jsx,ts,tsx}",
    "<rootDir>/src/**/*.{spec,test}.{js,jsx,ts,tsx}"
    ],
    "testEnvironment": "jsdom",
    "transform": {
    "^.+\\.(js|jsx|mjs|cjs|ts|tsx)$": "<rootDir>/config/jest/babelTransform.js",
    "^.+\\.css$": "<rootDir>/config/jest/cssTransform.js",
    "^(?!.*\\.(js|jsx|mjs|cjs|ts|tsx|css|json)$)": "<rootDir>/config/jest/fileTransform.js"
    },
    "transformIgnorePatterns": [
    "[/\\\\]node_modules[/\\\\].+\\.(js|jsx|mjs|cjs|ts|tsx)$",
    "^.+\\.module\\.(css|sass|scss)$"
    ],
    "modulePaths": [],
    "moduleNameMapper": {
    "^react-native$": "react-native-web",
    "^.+\\.module\\.(css|sass|scss)$": "identity-obj-proxy"
    },
    "moduleFileExtensions": [
    "web.js",
    "js",
    "web.ts",
    "ts",
    "web.tsx",
    "tsx",
    "json",
    "web.jsx",
    "jsx",
    "node"
    ],
    "watchPlugins": [
    "jest-watch-typeahead/filename",
    "jest-watch-typeahead/testname"
    ],
    "resetMocks": true
    },
    "babel": {
    "presets": [
    "react-app"
    ]
    }
    }
    ```
    hsuyeung
        2
    hsuyeung  
    OP
       2022-05-09 23:02:28 +08:00
    上 StackOverflow 上看了看也没有找着解决方案。
    hsuyeung
        3
    hsuyeung  
    OP
       2022-05-10 09:15:26 +08:00
    控制台:
    yarn install v1.22.18
    [1/4] Resolving packages...
    [2/4] Fetching packages...
    [3/4] Linking dependencies...
    warning Workspaces can only be enabled in private projects.
    [4/4] Building fresh packages...
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   5549 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 39ms · UTC 08:27 · PVG 16:27 · LAX 00:27 · JFK 03:27
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.