Actually proper solution
Update your CI deployment configuration:
npm config set '//registry.npmjs.org/:_authToken' "${NPM_TOKEN}"
npm publish
Remove this line from the .npmrc file:
//registry.npmjs.org/:_authToken=${NPM_TOKEN}
Example build config
You can see this solution used in practice in one of my GitHub repositories: https://github.com/Jezorko/lambda-simulator/blob/5882a5d738060c027b830bcc2d58824c5d27942b/.github/workflows/deploy.yml#L26-L27
The encrypted environment variable is an NPM token.
Why the other “solutions” are mere workarounds
I’ve seen answers here and under this question that recommend simply removing the variable setting line or .npmrc file entirely.
Thing is, the .npmrc file might not be ignored by your VCS system and modifying it might lead to accidental pushes to your project’s repository. Additionally, the file may contain other important settings.
The problem here is that .npmrc does not allow defaults when setting up environment variables. For example, if the following syntax was allowed, the issue would be non-existent:
//registry.npmjs.org/:_authToken=${NPM_TOKEN:-undefined}