0

I have created a new organisation on npm and I am trying to publish my react component as a scoped package so that my team can use the same component in-house in all other apps.

On running npm publish command I am getting the following

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:

my package.json looks like this

{
  "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 file looks like this

//.babelrc
{
  "presets": [
    "@babel/preset-react"
  ]
}

And .npmrc looks like this

registry=http://registry.npmjs.org/
scope=myscopename
@myscopename:registry=http://registry.npmjs.org

And I have also tried

  • login out and then login in again.
  • uninstalled node_modules and then re-installed them.
  • did npm update
  • cleared npm cache as well
RobC
  • 22,977
  • 20
  • 73
  • 80
Jasmohan Singh
  • 61
  • 3
  • 11

2 Answers2

0

I have solved the issue. I was trying to use .npmrc to set scope but that was not working the way I wanted it to work.

But running the command "npm init --scope=your-scope" did the job. This command rebuilds the package.json file. I was not running the command at the first place because I was not sure if I need to run "npm init" if I already have a package.json in place. And I was afraid that it might reset the dependencies of my package but that is not the case. It keeps the dependencies intact.

Jasmohan Singh
  • 61
  • 3
  • 11
-1

Set private field (at 3rd line) in package.json file to false.

  • 1
    Please check the title of the problem. It specifically says "Private NPM Package". If we set the private field to false then this will become a public package. – Jasmohan Singh Feb 26 '21 at 10:51