Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to replace env in config: ${NPM_AUTH_TOKEN} after adding cache: npm #285

Closed
yoavain-sundaysky opened this issue Jul 4, 2021 · 3 comments
Assignees

Comments

@yoavain-sundaysky
Copy link

After adding
cache: npm
I'm getting this error

Error: Failed to replace env in config: ${NPM_AUTH_TOKEN}

.npmrc file:

//registry.npmjs.org/:_authToken=${NPM_AUTH_TOKEN}

Environment: Windows
node version: 12.x

Here's a sample failed run:
https://github.com/yoavain/create-windowless-app/pull/875/checks?check_run_id=2982161723

Full error:

Run actions/setup-node@v2.2.0
  with:
    node-version: 12.x
    cache: npm
    always-auth: false
    check-latest: false
    token: ***
Found in cache @ C:\hostedtoolcache\windows\node\12.22.1\x64
C:\Windows\system32\cmd.exe /D /S /C "C:\hostedtoolcache\windows\node\12.22.1\x64\npm.cmd config get cache"
Error: Failed to replace env in config: ${NPM_AUTH_TOKEN}
    at C:\hostedtoolcache\windows\node\12.22.1\x64\node_modules\npm\lib\config\core.js:415:13
    at String.replace (<anonymous>)
    at envReplace (C:\hostedtoolcache\windows\node\12.22.1\x64\node_modules\npm\lib\config\core.js:411:12)
    at parseField (C:\hostedtoolcache\windows\node\12.22.1\x64\node_modules\npm\lib\config\core.js:389:7)
    at C:\hostedtoolcache\windows\node\12.22.1\x64\node_modules\npm\lib\config\core.js:330:24
    at Array.forEach (<anonymous>)
    at Conf.add (C:\hostedtoolcache\windows\node\12.22.1\x64\node_modules\npm\lib\config\core.js:328:23)
    at ConfigChain.addString (C:\hostedtoolcache\windows\node\12.22.1\x64\node_modules\npm\node_modules\config-chain\index.js:244:8)
    at Conf.<anonymous> (C:\hostedtoolcache\windows\node\12.22.1\x64\node_modules\npm\lib\config\core.js:316:10)
    at C:\hostedtoolcache\windows\node\12.22.1\x64\node_modules\npm\node_modules\graceful-fs\graceful-fs.js:123:16
C:\hostedtoolcache\windows\node\12.22.1\x64\node_modules\npm\lib\npm.js:59
      throw new Error('npm.load() required')
      ^

Error: npm.load() required
    at Object.get (C:\hostedtoolcache\windows\node\12.22.1\x64\node_modules\npm\lib\npm.js:59:13)
    at process.errorHandler (C:\hostedtoolcache\windows\node\12.22.1\x64\node_modules\npm\lib\utils\error-handler.js:208:32)
    at process.emit (events.js:314:20)
    at process._fatalException (internal/process/execution.js:165:25)
Error: The process 'C:\hostedtoolcache\windows\node\12.22.1\x64\npm.cmd' failed with exit code 7
@dmitry-shibanov
Copy link
Contributor

Hello @yoavain-sundaysky. Thank you for your report. As I know .npmrc file used as a configuration file and applies to command of npm. We use npm config get cache to identify directory for caching, that is why you get errors that NPM_AUTH_TOKEN is not assigned. You can add NPM_AUTH_TOKEN as environment variable.

    - name: Setup NodeJS
      uses: actions/setup-node@v2.2.0
      with:
        node-version: ${{ matrix.node-version }}
       cache: npm
      env:
        NPM_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}

Also you can specify NPM_AUTH_TOKEN as a job environment variable.

@yoavain
Copy link

yoavain commented Jul 5, 2021

Thanks! That works.
Maybe this should be in the README

@dmitry-shibanov
Copy link
Contributor

Hello @yoavain. Thank you for your response. For now I think we should not update documentation. If we see more issues related to this case, we'll update documentation.
For now I'm closing the issue.

vinayakkulkarni added a commit to geoql/expenses that referenced this issue Oct 3, 2021
domoritz added a commit to vega/vega-tooltip that referenced this issue Aug 12, 2022
deining pushed a commit to deining/setup-node that referenced this issue Nov 9, 2023
* docs: update README.md [skip ci]

* docs: update .all-contributorsrc [skip ci]

Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants