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

🐛 BUG: C3 fails if npm info returns warning messages as well as the expected output #4729

Closed
petebacondarwin opened this issue Jan 9, 2024 · 7 comments · Fixed by #4771 or #4826
Assignees
Labels
bug Something that isn't working

Comments

@petebacondarwin
Copy link
Contributor

Which Cloudflare product(s) does this pertain to?

C3

What version(s) of the tool(s) are you using?

[C3] latest

What version of Node are you using?

???

What operating system are you using?

Windows

Describe the Bug

As reported by Daniel Benhamou, if npm is configured strangely the warnings get returned as part of the call to npm info that C3 makes. This can result in semver complaining about the length of the string it is parsing. E.g.

npm create cloudflare@latest
...
TypeError: version is longer than 256 characters.

This is due to the semver library trying to parse the warning that is included in the npm command line output: https://github.com/npm/node-semver/blob/816c7b2cbfcb1986958a290f941eddfd0441139e/classes/semver.js#L24

Please provide a link to a minimal reproduction

No response

Please provide any relevant error logs

The workaround was to remove configuration that caused the warnings.

But the better long term solution would be for C3 to access the npm REST API directly rather than using the command line tool.

@petebacondarwin petebacondarwin added the bug Something that isn't working label Jan 9, 2024
@github-project-automation github-project-automation bot moved this to Untriaged in workers-sdk Jan 9, 2024
@petebacondarwin petebacondarwin moved this from Untriaged to Backlog in workers-sdk Jan 9, 2024
@mrbbot
Copy link
Contributor

mrbbot commented Jan 9, 2024

Might also be a good idea to soft-fail if this version check fails, and proceed with the installed version/a known compatibility date otherwise 👍

@petebacondarwin
Copy link
Contributor Author

["npm", "info", "create-cloudflare@latest", "dist-tags.latest"],

@dario-piotrowicz
Copy link
Member

I think we should just fetch from the npm registry as we already do for the workerd compat date (#4627)

petebacondarwin added a commit that referenced this issue Jan 18, 2024
When create-cloudflare starts up, it checks to see if the version being run
is the latest available on npm.

Previously this check used `npm info` to look up the version.
But was prone to failing if that command returned additional unexpected output
such as warnings.

Now we make a fetch request to the npm REST API directly for the latest version,
which does not have the problem of unexpected warnings.

Since the same approach is used to compute the latest version of workerd, the
function to do this has been put into a helper.

Fixes #4729
@petebacondarwin petebacondarwin moved this from Backlog to In Progress in workers-sdk Jan 18, 2024
petebacondarwin added a commit that referenced this issue Jan 18, 2024
When create-cloudflare starts up, it checks to see if the version being run
is the latest available on npm.

Previously this check used `npm info` to look up the version.
But was prone to failing if that command returned additional unexpected output
such as warnings.

Now we make a fetch request to the npm REST API directly for the latest version,
which does not have the problem of unexpected warnings.

Since the same approach is used to compute the latest version of workerd, the
function to do this has been put into a helper.

Fixes #4729
@petebacondarwin petebacondarwin moved this from In Progress to In Review in workers-sdk Jan 18, 2024
petebacondarwin added a commit that referenced this issue Jan 18, 2024
When create-cloudflare starts up, it checks to see if the version being run
is the latest available on npm.

Previously this check used `npm info` to look up the version.
But was prone to failing if that command returned additional unexpected output
such as warnings.

Now we make a fetch request to the npm REST API directly for the latest version,
which does not have the problem of unexpected warnings.

Since the same approach is used to compute the latest version of workerd, the
function to do this has been put into a helper.

Fixes #4729
petebacondarwin added a commit that referenced this issue Jan 19, 2024
When create-cloudflare starts up, it checks to see if the version being run
is the latest available on npm.

Previously this check used `npm info` to look up the version.
But was prone to failing if that command returned additional unexpected output
such as warnings.

Now we make a fetch request to the npm REST API directly for the latest version,
which does not have the problem of unexpected warnings.

Since the same approach is used to compute the latest version of workerd, the
function to do this has been put into a helper.

Fixes #4729
petebacondarwin added a commit that referenced this issue Jan 22, 2024
When create-cloudflare starts up, it checks to see if the version being run
is the latest available on npm.

Previously this check used `npm info` to look up the version.
But was prone to failing if that command returned additional unexpected output
such as warnings.

Now we make a fetch request to the npm REST API directly for the latest version,
which does not have the problem of unexpected warnings.

Since the same approach is used to compute the latest version of workerd, the
function to do this has been put into a helper.

Fixes #4729
petebacondarwin added a commit that referenced this issue Jan 22, 2024
When create-cloudflare starts up, it checks to see if the version being run
is the latest available on npm.

Previously this check used `npm info` to look up the version.
But was prone to failing if that command returned additional unexpected output
such as warnings.

Now we make a fetch request to the npm REST API directly for the latest version,
which does not have the problem of unexpected warnings.

Since the same approach is used to compute the latest version of workerd, the
function to do this has been put into a helper.

Fixes #4729
@artmen1516
Copy link

Hello, any workaround for this issue in the meantime? I'm getting the error described in this issue
when using --verbose flag

> npm create cloudflare@latest --verbose
╰  ERROR  TypeError: version is longer than 256 characters

Screenshot 2024-01-22 at 9 32 22 AM

@petebacondarwin
Copy link
Contributor Author

You can try using the pre-release version from the PR:

npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/7614864002/npm-package-create-cloudflare-4771 --no-auto-update

@petebacondarwin
Copy link
Contributor Author

Or in fact explicitly tell C3 not to get the latest version:

npm create cloudflare@latest -- --auto-update=false

@artmen1516
Copy link

Thanks @petebacondarwin, both approaches worked 👍🏼

petebacondarwin added a commit that referenced this issue Jan 23, 2024
When create-cloudflare starts up, it checks to see if the version being run
is the latest available on npm.

Previously this check used `npm info` to look up the version.
But was prone to failing if that command returned additional unexpected output
such as warnings.

Now we make a fetch request to the npm REST API directly for the latest version,
which does not have the problem of unexpected warnings.

Since the same approach is used to compute the latest version of workerd, the
function to do this has been put into a helper.

Fixes #4729
petebacondarwin added a commit that referenced this issue Jan 23, 2024
When create-cloudflare starts up, it checks to see if the version being run
is the latest available on npm.

Previously this check used `npm info` to look up the version.
But was prone to failing if that command returned additional unexpected output
such as warnings.

Now we make a fetch request to the npm REST API directly for the latest version,
which does not have the problem of unexpected warnings.

Since the same approach is used to compute the latest version of workerd, the
function to do this has been put into a helper.

Fixes #4729
petebacondarwin added a commit that referenced this issue Jan 23, 2024
When create-cloudflare starts up, it checks to see if the version being run
is the latest available on npm.

Previously this check used `npm info` to look up the version.
But was prone to failing if that command returned additional unexpected output
such as warnings.

Now we make a fetch request to the npm REST API directly for the latest version,
which does not have the problem of unexpected warnings.

Since the same approach is used to compute the latest version of workerd, the
function to do this has been put into a helper.

Fixes #4729
petebacondarwin added a commit that referenced this issue Jan 24, 2024
When create-cloudflare starts up, it checks to see if the version being run
is the latest available on npm.

Previously this check used `npm info` to look up the version.
But was prone to failing if that command returned additional unexpected output
such as warnings.

Now we make a fetch request to the npm REST API directly for the latest version,
which does not have the problem of unexpected warnings.

Since the same approach is used to compute the latest version of workerd, the
function to do this has been put into a helper.

Fixes #4729
petebacondarwin added a commit that referenced this issue Jan 24, 2024
When create-cloudflare starts up, it checks to see if the version being run
is the latest available on npm.

Previously this check used `npm info` to look up the version.
But was prone to failing if that command returned additional unexpected output
such as warnings.

Now we make a fetch request to the npm REST API directly for the latest version,
which does not have the problem of unexpected warnings.

Since the same approach is used to compute the latest version of workerd, the
function to do this has been put into a helper.

Fixes #4729
petebacondarwin added a commit that referenced this issue Jan 24, 2024
* fix: correctly find the latest version of create-cloudflare

When create-cloudflare starts up, it checks to see if the version being run
is the latest available on npm.

Previously this check used `npm info` to look up the version.
But was prone to failing if that command returned additional unexpected output
such as warnings.

Now we make a fetch request to the npm REST API directly for the latest version,
which does not have the problem of unexpected warnings.

Since the same approach is used to compute the latest version of workerd, the
function to do this has been put into a helper.

Fixes #4729

* Log C3 "more info" to console.error rather than console.log

The yargs help info is set to error, so this makes it consistent
and simpler to spy on in tests.
@github-project-automation github-project-automation bot moved this from In Review to Done in workers-sdk Jan 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something that isn't working
Projects
None yet
5 participants