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

[NEXT-832] Dev Server NPM error code ENOWORKSPACES #47121

Closed
1 task done
joepetrillo opened this issue Mar 14, 2023 · 25 comments · Fixed by #68522
Closed
1 task done

[NEXT-832] Dev Server NPM error code ENOWORKSPACES #47121

joepetrillo opened this issue Mar 14, 2023 · 25 comments · Fixed by #68522
Labels
bug Issue was opened via the bug report template. locked Upstream Related to using Next.js with a third-party dependency. (e.g., React, UI/icon libraries, etc.).

Comments

@joepetrillo
Copy link

joepetrillo commented Mar 14, 2023

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
      Platform: darwin
      Arch: arm64
      Version: Darwin Kernel Version 22.2.0: Fri Nov 11 02:03:51 PST 2022; root:xnu-8792.61.2~4/RELEASE_ARM64_T6000
    Binaries:
      Node: 18.15.0
      npm: 9.6.1
      Yarn: N/A
      pnpm: N/A
    Relevant packages:
      next: 13.2.5-canary.3
      eslint-config-next: 13.2.4
      react: 18.2.0
      react-dom: 18.2.0

Which area(s) of Next.js are affected? (leave empty if unsure)

Dev server and NPM

Link to the code that reproduces this issue

https://github.com/joepetrillo/workspace-issue

To Reproduce

Clone the repo then npm install then cd reproduction-app then npm run dev

image

Describe the Bug

I have determined that this error happens when a nextjs (versions after 13.1.6) dev server runs in an npm workspace.

npm config get registry is getting called sometime during the dev server startup and is throwing an error since it is not supported in workspaces.

error code ENOWORKSPACES
error This command does not support workspaces.

I initially thought this could be a turborepo issue, but it is not. More details are in the issue I initially opened (linked below).

vercel/turborepo#4183

And here is a sample error log:

0 verbose cli /Users/jpetrillo/Library/Application Support/fnm/node-versions/v18.15.0/installation/bin/node /Users/jpetrillo/Library/Caches/fnm_multishells/18620_1678811038524/bin/npm
1 info using [email protected]
2 info using [email protected]
3 timing npm:load:whichnode Completed in 0ms
4 timing config:load:defaults Completed in 0ms
5 timing config:load:file:/Users/jpetrillo/Library/Application Support/fnm/node-versions/v18.15.0/installation/lib/node_modules/npm/npmrc Completed in 1ms
6 timing config:load:builtin Completed in 1ms
7 timing config:load:cli Completed in 0ms
8 timing config:load:env Completed in 0ms
9 info found workspace root at /Users/jpetrillo/Documents/Projects/workspace-bug
10 timing config:load:file:/Users/jpetrillo/Documents/Projects/workspace-bug/.npmrc Completed in 0ms
11 timing config:load:project Completed in 3ms
12 timing config:load:file:/Users/jpetrillo/.npmrc Completed in 0ms
13 timing config:load:user Completed in 0ms
14 timing config:load:file:/Users/jpetrillo/Library/Application Support/fnm/node-versions/v18.15.0/installation/etc/npmrc Completed in 0ms
15 timing config:load:global Completed in 0ms
16 timing config:load:setEnvs Completed in 0ms
17 timing config:load Completed in 5ms
18 timing npm:load:configload Completed in 5ms
19 timing npm:load:mkdirpcache Completed in 0ms
20 timing npm:load:mkdirplogs Completed in 0ms
21 verbose title npm config get registry
22 verbose argv "config" "get" "registry"
23 timing npm:load:setTitle Completed in 5ms
24 timing config:load:flatten Completed in 1ms
25 timing npm:load:display Completed in 1ms
26 verbose logfile logs-max:10 dir:/Users/jpetrillo/.npm/_logs/2023-03-14T16_37_32_128Z-
27 verbose logfile /Users/jpetrillo/.npm/_logs/2023-03-14T16_37_32_128Z-debug-0.log
28 timing npm:load:logFile Completed in 2ms
29 timing npm:load:timers Completed in 0ms
30 timing npm:load:configScope Completed in 0ms
31 timing npm:load Completed in 15ms
32 timing command:config Completed in 0ms
33 verbose stack Error: This command does not support workspaces.
33 verbose stack     at Config.cmdExec (/Users/jpetrillo/Library/Application Support/fnm/node-versions/v18.15.0/installation/lib/node_modules/npm/lib/base-command.js:123:29)
33 verbose stack     at Npm.exec (/Users/jpetrillo/Library/Application Support/fnm/node-versions/v18.15.0/installation/lib/node_modules/npm/lib/npm.js:154:20)
33 verbose stack     at async module.exports (/Users/jpetrillo/Library/Application Support/fnm/node-versions/v18.15.0/installation/lib/node_modules/npm/lib/cli.js:134:5)
34 verbose cwd /Users/jpetrillo/Documents/Projects/workspace-bug/reproduction-app
35 verbose Darwin 22.2.0
36 verbose node v18.15.0
37 verbose npm  v9.6.1
38 error code ENOWORKSPACES
39 error This command does not support workspaces.
40 verbose exit 1
41 timing npm Completed in 21ms
42 verbose code 1
43 error A complete log of this run can be found in:
43 error     /Users/jpetrillo/.npm/_logs/2023-03-14T16_37_32_128Z-debug-0.log

Expected Behavior

No error

Which browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

NEXT-832

@joepetrillo joepetrillo added the bug Issue was opened via the bug report template. label Mar 14, 2023
@joepetrillo joepetrillo changed the title NPM error code ENOWORKSPACES NextJS NPM error code ENOWORKSPACES Mar 14, 2023
@joepetrillo joepetrillo changed the title NextJS NPM error code ENOWORKSPACES NPM error code ENOWORKSPACES Mar 14, 2023
@joepetrillo joepetrillo changed the title NPM error code ENOWORKSPACES Dev Server NPM error code ENOWORKSPACES Mar 14, 2023
@balazsorban44
Copy link
Member

I cannot reproduce it on my machine, even with next@canary, but this might be related to

const output = execSync(`${pkgManager} config get registry`)

Which was added as part of #44234 to show the version of Next.js in the error overlay.

The first release was 13.1.7-canary.18 though, so it's unclear how you can reproduce this in 13.1.6.

Could you be able to track down the exact canary version this broke? 🙏 As said, I, unfortunately, cannot reproduce. 🤔 It's strange because the command is also wrapped in try..catch so in theory it should not break.

The getRegistry function is called in a few places, it might be related to one of them:

image

@balazsorban44 balazsorban44 changed the title Dev Server NPM error code ENOWORKSPACES [NEXT-832] Dev Server NPM error code ENOWORKSPACES Mar 16, 2023
@joepetrillo
Copy link
Author

joepetrillo commented Mar 16, 2023

Thanks for looking into this! I should have been more clear - this error does NOT happen on 13.1.6. Every major release AFTER 13.1.6 does throw this error. I had a few other people try to reproduce and they got the same error, it’s strange it’s not happening for you.

I will try to figure out exactly what canary version it started on.

@balazsorban44
Copy link
Member

balazsorban44 commented Mar 16, 2023

Yeah, I understood your message, the fuzzy part was how it was happening between 13.1.6 - 13.1.7-canary.18, since the change (which I think is relevant) was added in 13.1.17-canary.18.

Tracking down the exact canary version will help a lot though! 🙏

@joepetrillo
Copy link
Author

joepetrillo commented Mar 16, 2023

Ok so I just tested each version and it starts happening at exactly 13.1.7-canary.18 like you thought!

image

@joepetrillo
Copy link
Author

If anyone else is able to reproduce this, it could be helpful to know if you are using any sort of node package manager or if you have any sort of .npmrc config. I will try to find a few others who have already reproduced this to give me their info.

@ifeltsweet
Copy link

We run into the exact same issue and we are using n.

@sunaurus
Copy link

I'm seeing the same error on next 13.2.4.
I'm using nvm version 0.39.3 with node v18.15.0.

Running npm config get registry in my nextjs workspace does indeed produce the exact same error. It works without issues when running in the root directory that contains all the workspaces.

@tonypine
Copy link

Also happening here running next 13.2.4, with turbo 1.4.3, node 18 and npm 9.5.0

@davecarlson
Copy link
Contributor

Still seeing this on

next 13.2.4
turbo 1.8.5
npm  9.5.0

@goesta
Copy link

goesta commented Mar 27, 2023

Getting the same error while following the Turborepo tutorial:
Not using a version manager, installed node with homebrew.
Next Version: "next": "^13.1.1", (13.2.4)

31 timing npm:load Completed in 14ms
32 timing command:config Completed in 1ms
33 verbose stack Error: This command does not support workspaces.
33 verbose stack     at Config.cmdExec (/opt/homebrew/lib/node_modules/npm/lib/base-command.js:123:29)
33 verbose stack     at Npm.exec (/opt/homebrew/lib/node_modules/npm/lib/npm.js:154:20)
33 verbose stack     at async module.exports (/opt/homebrew/lib/node_modules/npm/lib/cli.js:134:5)
34 verbose cwd /Users/x/Projects/test/apps/web
35 verbose Darwin 22.3.0
36 verbose node v19.8.1
37 verbose npm  v9.6.2
38 error code ENOWORKSPACES
39 error This command does not support workspaces.
40 verbose exit 1

@jiby-aurum
Copy link

I get the error with 3.1.6 also on first dev server start, seemingly it tries to patch lock file

ready - started server on 0.0.0.0:3030, url: http://localhost:3030
info  - Loaded env from /Users/jibyjose/Projects/aurum-one/web/dashboard/.env
warn  - The `app` directory is experimental. To enable, add `appDir: true` to your `next.config.js` configuration under `experimental`. See https://nextjs.org/docs/messages/experimental-app-dir-config
warn  - The `app` directory is experimental. To enable, add `appDir: true` to your `next.config.js` configuration under `experimental`. See https://nextjs.org/docs/messages/experimental-app-dir-config
info  - automatically enabled Fast Refresh for 1 custom loader
warn  - Found lockfile missing swc dependencies, patching...
npm ERR! code ENOWORKSPACES
npm ERR! This command does not support workspaces.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/jibyjose/.npm/_logs/2023-03-28T13_55_04_964Z-debug-0.log
event - compiled client and server successfully in 2s (4135 modules)
warn  - Lockfile was successfully patched, please run "npm install" to ensure @next/swc dependencies are downloaded

@joepetrillo
Copy link
Author

I have continued using it with this error and everything seems to work fine - obviously would still be nice to have fixed.

@tgaeta
Copy link

tgaeta commented Apr 6, 2023

I also receive the same error when I spin up a dev server on a turborepo/next/npm project. Everything still builds and runs like @joepetrillo stated.

Error:

npm ERR! code ENOWORKSPACES
npm ERR! This command does not support workspaces.

npm ERR! A complete log of this run can be found in: ...

Package versions:

"next": "13.2.4",
"react": "18.2.0",
"react-dom": "18.2.0",
"turbo": "1.8.3",

node/npm versions:

node --version
v18.15.0

npm --version
9.5.0

@jacobpgn
Copy link
Contributor

jacobpgn commented Apr 6, 2023

Hey folks! I've just seen this same error with another developer I'm working with.

We both have very similar developer environment setups, but they were seeing ENOWORKSPACES when running next dev for an npm workspace via npm run dev -w=client, and I was not seeing any error. This is a brand new project we weren't expecting any issues with, so we've investigated why our systems were behaving differently.

Following the comments above pointing at npm config get registry and recent changes to getRegistry, I added some debugging to my local Next package so we could step through the code. getRegistry first tries to find out which package manager is being used, so we step through getPkgManager:

  1. Check for lockfiles falls through, as npm workspaces don't have their own lockfiles.
  2. Check for user agent falls through with no matches (mine looks like npm/9.5.0 node/v18.15.0 darwin arm64 workspaces/true)
  3. ⚠️ Check to see if yarn is installed passes. I have yarn installed, though I'm not using it for this project, so getPkgManager returns yarn for an npm workspace. My friend does not have yarn installed, so it falls to return 'npm' by default.

Finally, in getRegistry my machine runs yarn config get registry and the other machine runs npm config get registry.

yarn config get registry does not raise this workspace error, but npm config get registry does 😅

My guess is that the other folks here unable to reproduce the error have either yarn or pnpm installed, whereas people seeing the error do not.

Perhaps getRegistry should be updated to silently swallow this error? I'd also propose a fix for getPkgManager to identify npm in this case, but in practice that might just mean that more people see an unhelpful error!

potential quick fix for users

Run npx next telemetry disable to disable Next telemetry. That skips this whole check so you'll see no error, and I've also found it's made next dev start up faster for me 🙂

@tgaeta
Copy link

tgaeta commented Apr 6, 2023

npx next telemetry disable

Yep - fixed it for me!!! 🎉

@joepetrillo
Copy link
Author

joepetrillo commented Apr 6, 2023

Disabling telemetry fixes this for me! I can also confirm that I do not have yarn or pnpm installed.

I guess I’m not sharing any data with Vercel for the time being 😆

@nyfever007
Copy link

this did the trick. thanks

@thany
Copy link

thany commented Apr 19, 2023

Ran into the same issue, disabling telemetry worked around the issue... On my pc.

Other people in my team are still experiencing this issue. So, despite positive comments, it's not actually fixed yet.

@siobh9
Copy link

siobh9 commented May 3, 2023

jacobpgn

Thank you so much for this - super helpful!

@lmaero
Copy link

lmaero commented Jul 7, 2023

Hey folks! I've just seen this same error with another developer I'm working with.

We both have very similar developer environment setups, but they were seeing ENOWORKSPACES when running next dev for an npm workspace via npm run dev -w=client, and I was not seeing any error. This is a brand new project we weren't expecting any issues with, so we've investigated why our systems were behaving differently.

Following the comments above pointing at npm config get registry and recent changes to getRegistry, I added some debugging to my local Next package so we could step through the code. getRegistry first tries to find out which package manager is being used, so we step through getPkgManager:

  1. Check for lockfiles falls through, as npm workspaces don't have their own lockfiles.
  2. Check for user agent falls through with no matches (mine looks like npm/9.5.0 node/v18.15.0 darwin arm64 workspaces/true)
  3. ⚠️ Check to see if yarn is installed passes. I have yarn installed, though I'm not using it for this project, so getPkgManager returns yarn for an npm workspace. My friend does not have yarn installed, so it falls to return 'npm' by default.

Finally, in getRegistry my machine runs yarn config get registry and the other machine runs npm config get registry.

yarn config get registry does not raise this workspace error, but npm config get registry does 😅

My guess is that the other folks here unable to reproduce the error have either yarn or pnpm installed, whereas people seeing the error do not.

Perhaps getRegistry should be updated to silently swallow this error? I'd also propose a fix for getPkgManager to identify npm in this case, but in practice that might just mean that more people see an unhelpful error!

potential quick fix for users

Run npx next telemetry disable to disable Next telemetry. That skips this whole check so you'll see no error, and I've also found it's made next dev start up faster for me 🙂

Thank you!

As an alternative, if you don't want to use npx next telemetry disable you can set this environment variable inside your .env file NEXT_TELEMETRY_DISABLED=1

@DeepakR63
Copy link

Thank you so much...! I have faced the same issue, that can resolved with npx next telemetry disable

uonr added a commit to mythal/boluo that referenced this issue Apr 4, 2024
uonr added a commit to mythal/boluo that referenced this issue Apr 7, 2024
@balazsorban44 balazsorban44 added Upstream Related to using Next.js with a third-party dependency. (e.g., React, UI/icon libraries, etc.). and removed area: package manager labels Apr 17, 2024
@jiteshrajoriyaa
Copy link

But this fix only run the docs not the web.
Screenshot 2024-06-06 163537

murderteeth added a commit to yearn/ylockers-ui that referenced this issue Jun 24, 2024
next telemetry is just phone home stats for next org
not needed for your app.

disabling does this:
1 - speeds up cold start and compile a bit
2 - fixes a non-breaking error you only see in monorepos

vercel/next.js#47121
murderteeth added a commit to yearn/ylockers-ui that referenced this issue Jul 11, 2024
* Setup bun monorepo

* Freeze wagmi/viem and tanstack versions

* Add lib for shared ui and tools

* Add --heavy-deps package

* Disable next telemetry

next telemetry is just phone home stats for next org
not needed for your app.

disabling does this:
1 - speeds up cold start and compile a bit
2 - fixes a non-breaking error you only see in monorepos

vercel/next.js#47121
@nazarepiedady
Copy link

@joepetrillo, if your problem was already solved, you can close this issue to help to clean up the issues tab,

@devjiwonchoi
Copy link
Member

Thank you @jacobpgn, your insight really sped up the investigation. 👍🏻

Copy link
Contributor

This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 21, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template. locked Upstream Related to using Next.js with a third-party dependency. (e.g., React, UI/icon libraries, etc.).
Projects
None yet
Development

Successfully merging a pull request may close this issue.