[英]Not able to publish my react components as private npm package
我在 npm 上創建了一個新組織,並且我正在嘗試將我的反應組件發布為范圍 package,以便我的團隊可以在所有其他應用程序中內部使用相同的組件。
在運行npm publish
命令時,我得到以下信息
npm ERR! code EPRIVATE
npm ERR! This package has been marked as private
npm ERR! Remove the 'private' field from the package.json to publish it.
npm ERR! A complete log of this run can be found in:
我的 package.json 看起來像這樣
{
"name": "my-package-name",
"version": "1.0.0",
"private": true,
"main": "dist/AllExports.js",
"module": "dist/AllExports.js",
"dependencies": {
"@material-ui/core": "^4.11.2",
"@material-ui/icons": "^4.11.2",
"@testing-library/jest-dom": "^5.11.6",
"@testing-library/react": "^11.2.2",
"@testing-library/user-event": "^12.4.0",
"axios": "^0.21.0",
"package1217721": "^1.2.7",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-hook-form": "^6.13.0",
"react-redux": "^7.2.2",
"react-scripts": "4.0.1",
"redux": "^4.0.5",
"redux-persist": "^6.0.0",
"web-vitals": "^0.2.4"
},
"scripts": {
"start": "react-scripts start",
"build": "set NODE_ENV=production && rm -rf dist && mkdir dist && npx babel src/components --out-dir dist",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"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"
]
},
"proxy": "http://localhost:5000",
"devDependencies": {
"@babel/cli": "^7.12.10",
"@babel/preset-react": "^7.12.10"
}
}
and.babelrc 文件長這樣
//.babelrc
{
"presets": [
"@babel/preset-react"
]
}
And.npmrc 看起來像這樣
registry=http://registry.npmjs.org/
scope=myscopename
@myscopename:registry=http://registry.npmjs.org
而且我也試過
我已經解決了這個問題。 我試圖使用 .npmrc 來設置 scope 但這並沒有按照我想要的方式工作。
但是運行命令“npm init --scope=your-scope”完成了這項工作。 此命令重建 package.json 文件。 我一開始沒有運行該命令,因為如果我已經有 package.json,我不確定是否需要運行“npm init”。 而且我擔心它可能會重置我的 package 的依賴關系,但事實並非如此。 它使依賴項保持不變。
將 package.json 文件中的私有字段(第 3 行)設置為 false。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.