vercel / next.js

The React Framework
https://nextjs.org
MIT License
122.99k stars 26.28k forks source link

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

Open joepetrillo opened 1 year ago

joepetrillo commented 1 year ago

Verify 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).

https://github.com/vercel/turbo/issues/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 npm@9.6.1
2 info using node@v18.15.0
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

balazsorban44 commented 1 year ago

I cannot reproduce it on my machine, even with next@canary, but this might be related to https://github.com/vercel/next.js/blob/67aceea72ba1b20063078d887f90739301bc4a80/packages/next/src/lib/helpers/get-registry.ts#L13

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? :pray: As said, I, unfortunately, cannot reproduce. :thinking: 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

joepetrillo commented 1 year ago

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 commented 1 year ago

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! :pray:

joepetrillo commented 1 year ago

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

image
joepetrillo commented 1 year ago

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 commented 1 year ago

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

sunaurus commented 1 year ago

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 commented 1 year ago

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

davecarlson commented 1 year ago

Still seeing this on

next 13.2.4
turbo 1.8.5
npm  9.5.0
goesta commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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

tgaeta commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

npx next telemetry disable

Yep - fixed it for me!!! 🎉

joepetrillo commented 1 year ago

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 commented 1 year ago

this did the trick. thanks

thany commented 1 year ago

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.

seanmc9 commented 1 year ago

jacobpgn

Thank you so much for this - super helpful!

lmaero commented 1 year ago

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 commented 6 months ago

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

jiteshrajoriyaa commented 1 month ago

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