Skip to content

When .npmrc contains comments, the nuxi module add command fails. #880

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

Open
odanado opened this issue May 15, 2025 · 2 comments · May be fixed by #881
Open

When .npmrc contains comments, the nuxi module add command fails. #880

odanado opened this issue May 15, 2025 · 2 comments · May be fixed by #881

Comments

@odanado
Copy link

odanado commented May 15, 2025

When the .npmrc file contains a comment on the same line as a registry setting, the nuxi module add command fails.

.npmrc:

registry=https://registry.npmjs.org # test comment

Steps to reproduce:

$ git clone https://github.com/odan-sandbox/nuxt-module-npmrc-comment-error-repro
$ cd nuxt-module-npmrc-comment-error-repro
$ npm i
$ npx nuxi module add pinia
[2:16:01]  ERROR  [GET] "https://registry.npmjs.org # test comment/@pinia/nuxt": <no response> Failed to parse URL from https://registry.npmjs.org # test comment/@pinia/nuxt

    at async $fetchRaw2 (node_modules/nuxi/dist/shared/nuxi.BzZJv2UC.mjs:371:14)
    at async $fetch2 (node_modules/nuxi/dist/shared/nuxi.BzZJv2UC.mjs:417:15)
    at async resolveModule (node_modules/nuxi/dist/chunks/add2.mjs:315:22)
    at async Promise.all (index 0)
    at async Object.setup (node_modules/nuxi/dist/chunks/add2.mjs:150:34)
    at async runCommand$1 (node_modules/nuxi/dist/shared/nuxi.BlFGnQYG.mjs:1739:5)
    at async runCommand$1 (node_modules/nuxi/dist/shared/nuxi.BlFGnQYG.mjs:1758:11)
    at async runCommand$1 (node_modules/nuxi/dist/shared/nuxi.BlFGnQYG.mjs:1758:11)
    at async runMain$1 (node_modules/nuxi/dist/shared/nuxi.BlFGnQYG.mjs:1896:7)

  [cause]: Failed to parse URL from https://registry.npmjs.org # test comment/@pinia/nuxt

      at node:internal/deps/undici/undici:13510:13
      at async $fetchRaw2 (node_modules/nuxi/dist/shared/nuxi.BzZJv2UC.mjs:359:26)

    [cause]: Invalid URL

        at new URL (node:internal/url:818:25)
        at new Request (node:internal/deps/undici/undici:9586:25)
        at fetch (node:internal/deps/undici/undici:10315:25)
        at fetch (node:internal/deps/undici/undici:13508:10)
        at fetch (node:internal/bootstrap/web/exposed-window-or-worker:75:12)
        at node_modules/nuxi/dist/shared/nuxi.BzZJv2UC.mjs:451:58
        at $fetchRaw2 (node_modules/nuxi/dist/shared/nuxi.BzZJv2UC.mjs:359:32)
        at onError (node_modules/nuxi/dist/shared/nuxi.BzZJv2UC.mjs:280:16)
        at $fetchRaw2 (node_modules/nuxi/dist/shared/nuxi.BzZJv2UC.mjs:371:20)
        at async $fetch2 (node_modules/nuxi/dist/shared/nuxi.BzZJv2UC.mjs:417:15) 



[2:16:01]  ERROR  [GET] "https://registry.npmjs.org # test comment/@pinia/nuxt": <no response> Failed to parse URL from https://registry.npmjs.org # test comment/@pinia/nuxt

Expected behavior:

The command should ignore comments in .npmrc and proceed with the module installation.

Cause of the issue

It is likely that the .npmrc file is not correctly removing comments when parsing the registry setting.
There is a bug in the regular expression used in the getRegistryFromFile function.

async function getRegistryFromFile(paths: string[], scope: string | null) {

Possible solutions:

  • Modify the regular expression to account for the presence of comments.
  • Introduce confbox for parsing .npmrc.

I am interested in resolving this issue. If you can suggest a preferred solution, I would like to create a pull request to fix this bug.

@odanado odanado changed the title When .npmrc contains comments, the nuxi module add command fails. When .npmrc contains comments, the nuxi module add command fails. May 15, 2025
@pi0
Copy link
Member

pi0 commented May 15, 2025

using confbox is good idea. Also we might introduce a standard util for unjs/nypm to read npmrc config. (PR more than welcome)

@odanado
Copy link
Author

odanado commented May 15, 2025

Thank you for the suggestion.
Since modifying unjs/nypm might be a bit too time-consuming at this point, I would like to proceed with directly using confbox to handle .npmrc parsing in nuxi.
I will proceed with this approach and create a pull request. Feel free to review it.

@odanado odanado linked a pull request May 15, 2025 that will close this issue
6 tasks
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

Successfully merging a pull request may close this issue.

2 participants