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

nuxi init fails with yarn #217

Open
polarathene opened this issue Sep 22, 2023 · 11 comments
Open

nuxi init fails with yarn #217

polarathene opened this issue Sep 22, 2023 · 11 comments

Comments

@polarathene
Copy link

polarathene commented Sep 22, 2023

This still seems to be problematic.

If you have docker installed the reproduction should help you verify a proper fix going forward? Below is two failing cases and one that is successful with a bit of extra configuration (that nuxi init could configure).

⚡️ Nuxt Generation CLI Experience (nuxi v3.9.0)

Previous issues stating it had been resolved with 3.8:

Related issues on yarn support with nuxt:

❌ | Yarn 3.6.3 (defaults to nodeLinker: pnp)

ERROR Error: Command failed with exit code 1: corepack yarn install

# Reproducible nodejs environment:
$ docker run --rm -it --workdir /reproduction node:20-bookworm-slim bash

# Legacy yarn is global default:
$ yarn -v
v1.22.19

# `yarn -v` will match any yarn version specified in the `packageManager` field of `package.json`:
$ corepack enable

# If a `package.json` is not present (or is missing `packageManager` field), this sets the fallback version:
# (_Still requires corepack to have been enabled to be applicable_)
$ corepack prepare yarn@stable --activate

$ yarn -v
3.6.3

# Run `nuxi init` non-interactively via explicit options:
$ yarn dlx nuxi init --packageManager yarn --gitInit false .

➤ YN0000: ┌ Resolution step
➤ YN0032: │ fsevents@npm:2.3.3: Implicit dependencies on node-gyp are discouraged
➤ YN0000: └ Completed in 2s 406ms
➤ YN0000: ┌ Fetch step
➤ YN0000: └ Completed
➤ YN0000: ┌ Link step
➤ YN0000: │ ESM support for PnP uses the experimental loader API and is therefore experimental
➤ YN0000: └ Completed
➤ YN0000: Done with warnings in 2s 606ms

◐ Installing dependencies...
➤ YN0000: ┌ Resolution step
➤ YN0032: │ fsevents@npm:2.3.3: Implicit dependencies on node-gyp are discouraged
➤ YN0032: │ @parcel/watcher@npm:2.3.0: Implicit dependencies on node-gyp are discouraged
➤ YN0032: │ node-addon-api@npm:7.0.0: Implicit dependencies on node-gyp are discouraged
➤ YN0002: │ nuxt-app@workspace:. doesn't provide vite (p73f11), requested by @nuxt/devtools
➤ YN0000: │ Some peer dependencies are incorrectly met; run yarn explain peer-requirements <hash> for details, where <hash> is the six-letter p-prefixed code
➤ YN0000: └ Completed in 6s 967ms
➤ YN0000: ┌ Fetch step
➤ YN0013: │ yaml@npm:2.3.2 can't be found in the cache and will be fetched from the remote registry
➤ YN0013: │ yargs-parser@npm:21.1.1 can't be found in the cache and will be fetched from the remote registry
➤ YN0013: │ yargs@npm:17.7.2 can't be found in the cache and will be fetched from the remote registry
➤ YN0013: │ zhead@npm:2.1.1 can't be found in the cache and will be fetched from the remote registry
➤ YN0013: │ zip-stream@npm:5.0.1 can't be found in the cache and will be fetched from the remote registry
➤ YN0000: └ Completed in 1s 152ms
➤ YN0000: ┌ Link step
➤ YN0000: │ ESM support for PnP uses the experimental loader API and is therefore experimental
➤ YN0007: │ esbuild@npm:0.18.20 must be built because it never has been before or the last one failed
➤ YN0007: │ esbuild@npm:0.19.3 must be built because it never has been before or the last one failed
➤ YN0009: │ esbuild@npm:0.18.20 couldn't be built successfully (exit code 1, logs can be found here: /tmp/xfs-797ad338/build.log)
➤ YN0009: │ esbuild@npm:0.19.3 couldn't be built successfully (exit code 1, logs can be found here: /tmp/xfs-56d77649/build.log)
➤ YN0007: │ nuxt-app@workspace:. must be built because it never has been before or the last one failed
➤ YN0009: │ nuxt-app@workspace:. couldn't be built successfully (exit code 1, logs can be found here: /tmp/xfs-8ee15c2e/build.log)
➤ YN0000: └ Completed in 0s 646ms
➤ YN0000: Failed with errors in 8s 813ms

 ERROR  Error: Command failed with exit code 1: corepack yarn install

❌ | Yarn 1.22.19 (no PNP, uses node_modules)

error Couldn't find a package.json file in "/reproduction"

$ docker run --rm -it --workdir /reproduction node:20-bookworm-slim bash

# Fails (corepack is not enabled by default)
$ yarn dlx nuxi init --packageManager yarn --gitInit false .
yarn run v1.22.19
error Couldn't find a package.json file in "/reproduction"
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Try again (with corepack enabled):

ERROR Error: Command failed with exit code 1: corepack yarn install

$ docker run --rm -it --workdir /reproduction node:20-bookworm-slim bash
$ corepack enable

# `yarn dlx` will use a modern version of yarn to run,
# `nuxi init` will then run the global yarn which is still 1.22.19:
$ yarn dlx nuxi init --packageManager yarn --gitInit false .

➤ YN0000: ┌ Resolution step
➤ YN0032: │ fsevents@npm:2.3.3: Implicit dependencies on node-gyp are discouraged
➤ YN0000: └ Completed in 2s 342ms
➤ YN0000: ┌ Fetch step
➤ YN0013: │ wide-align@npm:1.1.5 can't be found in the cache and will be fetched from the remote registry
➤ YN0013: │ wrap-ansi@npm:7.0.0 can't be found in the cache and will be fetched from the remote registry
➤ YN0013: │ wrap-ansi@npm:8.1.0 can't be found in the cache and will be fetched from the remote registry
➤ YN0013: │ wrappy@npm:1.0.2 can't be found in the cache and will be fetched from the remote registry
➤ YN0013: │ yallist@npm:4.0.0 can't be found in the cache and will be fetched from the remote registry
➤ YN0000: └ Completed in 1s 331ms
➤ YN0000: ┌ Link step
➤ YN0000: │ ESM support for PnP uses the experimental loader API and is therefore experimental
➤ YN0000: └ Completed
➤ YN0000: Done with warnings in 3s 845ms

◐ Installing dependencies...
yarn install v1.22.19
info No lockfile found.
[1/4] Resolving packages...
[2/4] Fetching packages...
warning vscode-languageclient@7.0.0: The engine "vscode" appears to be invalid.
[3/4] Linking dependencies...
warning " > @nuxt/devtools@0.8.4" has unmet peer dependency "vite@*".
warning "@nuxt/devtools > vite-plugin-inspect@0.7.38" has unmet peer dependency "vite@^3.1.0 || ^4.0.0".
warning "@nuxt/devtools > vite-plugin-vue-inspector@3.7.1" has unmet peer dependency "vite@^3.0.0-0 || ^4.0.0-0".
warning "@nuxt/devtools > @nuxt/devtools-kit@0.8.4" has unmet peer dependency "vite@*".
[4/4] Building fresh packages...


error An unexpected error occurred: "/reproduction/node_modules/@esbuild-kit/core-utils/node_modules/esbuild, /reproduction/node_modules/vite/node_modules/esbuild: Cannot find module 'pnpapi'
Require stack:
- /root/.cache/node/corepack/yarn/1.22.19/lib/cli.js
Require stack:
- /root/.cache/node/corepack/yarn/1.22.19/lib/cli.js".



 ERROR  Error: Command failed with exit code 1: corepack yarn install

✔️ | Yarn 3.6.3 (change to nodeLinker: node-modules)

Installation completed.

Unless you have a way to resolve the issues above (Yarn project seems to want to keep legacy yarn as global by default, only using corepack to upgrade with yarn dlx and package.json approaches 🤷‍♂️ ), you may have to let users know to override the linker via ENV?

  • When choosing yarn you should probably set packageManager in package.json to ensure it installs with a newer version of yarn (when corepack is enabled).
  • Since Nuxt is not compatible with PnP linker, you'd additionally want to create a .yarnrc.yml with nodeLinker: node-modules as a minimum. Once you've configured pacakge.json:packageManager (must be semver like yarn@3.6.3, cannot use yarn@stable), you can run yarn config set nodeLinker node-modules to do this (if easier than manually creating the file).

EDIT: PNPM support has a related workaround in nuxi init with creating a .npmrc file.

$ docker run --rm -it --workdir /reproduction node:20-bookworm-slim bash

# Requirement (user should already have applied via reading yarn install docs):
$ corepack enable

# Temporary workaround until `package.json:packageManager` is implemented:
$ corepack prepare yarn@stable --activate

# Temporary linker workaround with ENV (`yarn config` not usable until `package.json` exists):
$ YARN_NODE_LINKER=node-modules yarn dlx nuxi init --packageManager yarn --gitInit false .

➤ YN0000: ┌ Resolution step
➤ YN0032: │ fsevents@npm:2.3.3: Implicit dependencies on node-gyp are discouraged
➤ YN0000: └ Completed in 3s 112ms
➤ YN0000: ┌ Fetch step
➤ YN0013: │ wide-align@npm:1.1.5 can't be found in the cache and will be fetched from the remote registry
➤ YN0013: │ wrap-ansi@npm:7.0.0 can't be found in the cache and will be fetched from the remote registry
➤ YN0013: │ wrap-ansi@npm:8.1.0 can't be found in the cache and will be fetched from the remote registry
➤ YN0013: │ wrappy@npm:1.0.2 can't be found in the cache and will be fetched from the remote registry
➤ YN0013: │ yallist@npm:4.0.0 can't be found in the cache and will be fetched from the remote registry
➤ YN0000: └ Completed in 1s 302ms
➤ YN0000: ┌ Link step
➤ YN0000: └ Completed
➤ YN0000: Done with warnings in 4s 562ms

◐ Installing dependencies...
➤ YN0000: ┌ Resolution step
➤ YN0032: │ fsevents@npm:2.3.3: Implicit dependencies on node-gyp are discouraged
➤ YN0032: │ @parcel/watcher@npm:2.3.0: Implicit dependencies on node-gyp are discouraged
➤ YN0032: │ node-addon-api@npm:7.0.0: Implicit dependencies on node-gyp are discouraged
➤ YN0002: │ nuxt-app@workspace:. doesn't provide vite (p73f11), requested by @nuxt/devtools
➤ YN0000: │ Some peer dependencies are incorrectly met; run yarn explain peer-requirements <hash> for details, where <hash> is the six-letter p-prefixed code
➤ YN0000: └ Completed in 9s 776ms
➤ YN0000: ┌ Fetch step
➤ YN0013: │ yaml@npm:2.3.2 can't be found in the cache and will be fetched from the remote registry
➤ YN0013: │ yargs-parser@npm:21.1.1 can't be found in the cache and will be fetched from the remote registry
➤ YN0013: │ yargs@npm:17.7.2 can't be found in the cache and will be fetched from the remote registry
➤ YN0013: │ zhead@npm:2.1.1 can't be found in the cache and will be fetched from the remote registry
➤ YN0013: │ zip-stream@npm:5.0.1 can't be found in the cache and will be fetched from the remote registry
➤ YN0000: └ Completed in 5s 537ms
➤ YN0000: ┌ Link step
➤ YN0007: │ esbuild@npm:0.19.3 must be built because it never has been before or the last one failed
➤ YN0007: │ esbuild@npm:0.18.20 must be built because it never has been before or the last one failed
➤ YN0007: │ nuxt-app@workspace:. must be built because it never has been before or the last one failed
➤ YN0000: └ Completed in 4s 253ms
➤ YN0000: Done with warnings in 19s 677ms
✔ Installation completed.

✨ Nuxt project has been created with the v3 template. Next steps:
 › Start development server with yarn run dev

NOTE: yarn dlx is not a great experience with nuxi since each time yarn takes about 4 seconds to prepare 🙄 (more of an issue with how yarn works, nothing to do with nuxi AFAIK)

Until nuxi init handles the additional yarn support changes. Users should:

  • Add the packageManager field to package.json (better portability).
  • Run yarn config set nodeLinker: node-modules (avoid requiring an ENV to override).
`yarn build` is successful

Important, since you can use yarn install in some nuxt project that is successful (with nodeLinker: pnp) but fails with yarn build.

$ YARN_NODE_LINKER=node-modules yarn build

Nuxt 3.7.3 with Nitro 2.6.3


ℹ Building client...
ℹ vite v4.4.9 building for production...
ℹ ✓ 112 modules transformed.
ℹ .nuxt/dist/client/manifest.json                   1.59 kB │ gzip:  0.31 kB
ℹ .nuxt/dist/client/_nuxt/error-500.c5df6088.css    1.95 kB │ gzip:  0.74 kB
ℹ .nuxt/dist/client/_nuxt/error-404.7fc72018.css    3.63 kB │ gzip:  1.12 kB
ℹ .nuxt/dist/client/_nuxt/entry.3c4ebcd6.css       12.13 kB │ gzip:  2.49 kB
ℹ .nuxt/dist/client/_nuxt/error-500.e5a1dd9d.js     1.88 kB │ gzip:  0.99 kB
ℹ .nuxt/dist/client/_nuxt/error-404.d5f8e506.js     6.53 kB │ gzip:  2.91 kB
ℹ .nuxt/dist/client/_nuxt/entry.8be7e620.js       197.90 kB │ gzip: 55.68 kB
ℹ ✓ built in 1.07s
✔ Client built in 1083ms


ℹ Building server...
ℹ vite v4.4.9 building SSR bundle for production...
ℹ ✓ 61 modules transformed.
ℹ .nuxt/dist/server/_nuxt/entry-styles.8755339a.mjs             0.08 kB
ℹ .nuxt/dist/server/_nuxt/error-404-styles.1e0dde27.mjs         0.15 kB
ℹ .nuxt/dist/server/_nuxt/error-500-styles.cf4b3e80.mjs         0.15 kB
ℹ .nuxt/dist/server/styles.mjs                                  0.46 kB
ℹ .nuxt/dist/server/_nuxt/island-renderer-bc39a2f4.js           1.06 kB │ map:   1.38 kB
ℹ .nuxt/dist/server/_nuxt/error-500-styles-1.mjs-8fa81fcc.js    2.17 kB │ map:   0.12 kB
ℹ .nuxt/dist/server/_nuxt/error-500-57cb52a6.js                 3.03 kB │ map:   3.77 kB
ℹ .nuxt/dist/server/_nuxt/error-404-styles-1.mjs-e0837f4f.js    3.86 kB │ map:   0.12 kB
ℹ .nuxt/dist/server/_nuxt/error-404-3dc619ae.js                 9.70 kB │ map:  18.97 kB
ℹ .nuxt/dist/server/_nuxt/entry-styles-1.mjs-8b8449e7.js       12.38 kB │ map:   0.11 kB
ℹ .nuxt/dist/server/server.mjs                                120.84 kB │ map: 163.36 kB
ℹ ✓ built in 536ms
✔ Server built in 543ms
✔ Generated public .output/public


ℹ Building Nitro Server (preset: node-server)
✔ Nitro server built
  ├─ .output/server/chunks/app/_nuxt/entry-styles.8755339a.mjs (12.4 kB) (2.61 kB gzip)
  ├─ .output/server/chunks/app/_nuxt/entry-styles.8755339a.mjs.map (312 B) (202 B gzip)
  ├─ .output/server/chunks/app/_nuxt/error-404-3dc619ae.mjs (9.81 kB) (3.12 kB gzip)
  ├─ .output/server/chunks/app/_nuxt/error-404-3dc619ae.mjs.map (8.02 kB) (1.97 kB gzip)
  ├─ .output/server/chunks/app/_nuxt/error-404-styles.1e0dde27.mjs (3.98 kB) (1.25 kB gzip)
  ├─ .output/server/chunks/app/_nuxt/error-404-styles.1e0dde27.mjs.map (346 B) (215 B gzip)
  ├─ .output/server/chunks/app/_nuxt/error-500-57cb52a6.mjs (3.07 kB) (1.35 kB gzip)
  ├─ .output/server/chunks/app/_nuxt/error-500-57cb52a6.mjs.map (1.68 kB) (600 B gzip)
  ├─ .output/server/chunks/app/_nuxt/error-500-styles.cf4b3e80.mjs (2.28 kB) (870 B gzip)
  ├─ .output/server/chunks/app/_nuxt/error-500-styles.cf4b3e80.mjs.map (346 B) (217 B gzip)
  ├─ .output/server/chunks/app/_nuxt/island-renderer-bc39a2f4.mjs (1.17 kB) (525 B gzip)
  ├─ .output/server/chunks/app/_nuxt/island-renderer-bc39a2f4.mjs.map (897 B) (413 B gzip)
  ├─ .output/server/chunks/app/client.manifest.mjs (2.52 kB) (461 B gzip)
  ├─ .output/server/chunks/app/client.manifest.mjs.map (2.04 kB) (405 B gzip)
  ├─ .output/server/chunks/app/server.mjs (123 kB) (23.7 kB gzip)
  ├─ .output/server/chunks/app/server.mjs.map (220 B) (164 B gzip)
  ├─ .output/server/chunks/app/styles.mjs (533 B) (269 B gzip)
  ├─ .output/server/chunks/app/styles.mjs.map (429 B) (216 B gzip)
  ├─ .output/server/chunks/error-500.mjs (4.26 kB) (1.82 kB gzip)
  ├─ .output/server/chunks/error-500.mjs.map (193 B) (157 B gzip)
  ├─ .output/server/chunks/handlers/renderer.mjs (12.9 kB) (4.08 kB gzip)
  ├─ .output/server/chunks/handlers/renderer.mjs.map (424 B) (227 B gzip)
  ├─ .output/server/chunks/multipart-parser.mjs (5.04 kB) (2.1 kB gzip)
  ├─ .output/server/chunks/multipart-parser.mjs.map (210 B) (167 B gzip)
  ├─ .output/server/chunks/nitro/node-server.mjs (260 kB) (66.5 kB gzip)
  ├─ .output/server/chunks/nitro/node-server.mjs.map (3.21 kB) (834 B gzip)
  ├─ .output/server/chunks/rollup/_virtual_spa-template.mjs (94 B) (100 B gzip)
  ├─ .output/server/chunks/rollup/_virtual_spa-template.mjs.map (112 B) (112 B gzip)
  ├─ .output/server/index.mjs (389 B) (210 B gzip)
  └─ .output/server/package.json (708 B) (294 B gzip)
Σ Total size: 2.33 MB (558 kB gzip)
✔ You can preview this build using node .output/server/index.mjs
@polarathene
Copy link
Author

Additional observation.

When using PNPM, .npmrc file is not created only in the project directory, but was also observed as being added to the root of the filesystem /.npmrc. It shouldn't do that, as the config is specific to Nuxt support?

@Extarys
Copy link

Extarys commented Oct 23, 2023

To keep track of stuff: Yarn 4 released now : https://yarnpkg.com/blog/release/4.0

@jits
Copy link
Contributor

jits commented Nov 1, 2023

@polarathene – that should be fixed by #272

@DarkLite1
Copy link

New user here and I've just installed node.js using nvm. Now that is done I'm following the Installation guide which says to execute:

npx nuxi@latest init <project-name>

This always yields the following error:
image

Because we don't have a project yet, there is no package.json to edit. So we executed the suggestion above without success:

yarn config set nodeLinker node-modules

We also tried yarn config set "strict-ssl" false but without success.

Is there something else we can do to get around this error? Thank you for your help.

@hotenov
Copy link

hotenov commented Apr 30, 2024

@DarkLite1 Hi! You can always set yarn setting(s) via environment variable(s) (although yarn doc page says: use them sparingly)

In your case, the following command should do what you need (on Linux/Unix machine):

Bash

YARN_NODE_LINKER='node-modules' npx nuxi init projectname

As I see you use Windows (as I do 😃 ), so choose your option:

PowerShell

$env:YARN_NODE_LINKER='node-modules'; npx nuxi init projectname; $env:YARN_NODE_LINKER=$null

CMD

set "YARN_NODE_LINKER=node-modules" & npx nuxi init projectname

Important: For CMD pay attention that we DO NOT use single quotes around node-modules. If you forgot to remove them, installation likely will fail with similar error outpt:

...
➤ YN0012: │ nuxt@npm:3.11.2 [1f046] isn't supported by any available linker
➤ YN0000: └ Completed
➤ YN0000: · Failed with errors in 8s 50ms

ERROR Error: Command failed with exit code 1: corepack yarn install

Note: These commands are not cluttered your system environment variables. Of course, you can set YARN_NODE_LINKER='node-modules' in advance (and if you use node_modules on all your projects). Then npx nuxi init should work without any preparation.

@jmarshall9120
Copy link

I'm having the same experience. Some extra info that might help with the cases. Let me know if this should be an separate ticket.

I originally had the same issue as CASE #2 that op posted. I solved in the end by upgrading Yarn. Now I have:

Yarn:

4.3.1

Node:

v20.`12.2

This has made the pnpapi dependencies resolve, but still leaves an issue running the basic install from docs

cd 'M:\\source'
yarn dlx nuxi@latest init AdvancedStorageV3

output:

➤ YN0000: · Yarn 4.3.1
➤ YN0000: ┌ Resolution step
➤ YN0085: │ + nuxi@npm:3.12.0, @isaacs/cliui@npm:8.0.2, @npmcli/agent@npm:2.2.2, @npmcli/fs@npm:3.1.1, and 90 more.
➤ YN0000: └ Completed in 1s 491ms
➤ YN0000: ┌ Fetch step
➤ YN0013: │ 93 packages were added to the project (+ 13.2 MiB).
➤ YN0000: └ Completed
➤ YN0000: ┌ Link step
➤ YN0000: │ ESM support for PnP uses the experimental loader API and is therefore experimental
➤ YN0000: └ Completed in 0s 286ms
➤ YN0000: · Done with warnings in 1s 972ms


✔ Which package manager would you like to use?
yarn


- If M: is intended to be a project, it might be that you forgot to list source/AdvancedStorageV3 in its workspace configuration.
- Finally, if M: is fine and you intend source/AdvancedStorageV3 to be treated as a completely separate project (not even a workspace), create an empty yarn.lock file in it.

$ yarn install [--json] [--immutable] [--immutable-cache] [--refresh-lockfile] [--check-cache] [--check-resolutions] [--inline-builds] [--mode #0]

 ERROR  Error: Command failed with exit code 1: corepack yarn install  

I'm guessing under the hood, the installer is passing the directory somewhere and its failing. Might be a windows/unix thing. Trying a bunch of workarounds now.

@jmarshall9120
Copy link

Okay, this is quite interesting. It turns out the error above is still related to the pnpapi error. Somehow, when upgrading yarn, yarn placed some packages at root M:. Those packages were creating the conflict above. When I removed those packages I got the pnpapi error again.

Rerunning, yarn set version stable, does not make those packages reappear.

@jmarshall9120
Copy link

The Yarn update is a false positive. It just caught old dependencies in the root then created a conflict for some reason. I get the same issue as OP Case 2 on Yarn 4.3.1.

@jmarshall9120
Copy link

@danielroe - yarn dev from ticket not found module @nuxt/kit when use yarn Plug'n'play #26750 doesn't work with work arounds on windows:

$env:YARN_NODE_LINKER='node-modules';
yarn dev

output

Usage Error: Couldn't find the node_modules state file - running an install might help (findPackageLocation)

$ yarn run [--inspect] [--inspect-brk] [-T,--top-level] [-B,--binaries-only] [--require #0] <scriptName> ...

Side Note:
Are we in a state where yarn + nuxt is now un-installable? I got into this trying to do some simple tests on a clean install. This ticket looks like a blocker.

@danielroe
Copy link
Member

That seems like a yarn issue, not a Nuxt one.

@charliebeckstrand
Copy link

After upgrading Yarn to 4.4.0, I was also getting this error when trying to nuxi init:

ERROR Error: Command failed with exit code 1: corepack yarn install

I fixed it by adding this to my .yarnrc.yml file:

nodeLinker: node-modules

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

8 participants