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

fix: wrong Git clone command & package/tsconfig.json configuration #835

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

TechQuery
Copy link

@TechQuery TechQuery commented Nov 28, 2023

Description

@vercel

Document bug

git clone can't download a GitHub folder, so the command in this Example's ReadMe will throw error:

$ git clone https://github.com/vercel/examples/tree/main/solutions/node-hello-world
Cloning into 'node-hello-world'...
fatal: repository 'https://github.com/vercel/examples/tree/main/solutions/node-hello-world/' not found

A Node.js CLI tool get-git-folder is a good alternative.

Configuration bug

If you run vercel dev in Node.js LTS (18+), and then call http://localhost:3000/api/hello, it will throw an error:

Error: Cannot use import statement outside a module

so, ESM is first choice for new Node.js projects.

But, TS with ESM will failed after deployment:

ReferenceError: exports is not defined in ES module scope
This file is being treated as an ES module because it has a '.js' file extension and '/var/task/package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
    at file:///var/task/api/hello.js:2:23
    at ModuleJob.run (node:internal/modules/esm/module_job:194:25)
INIT_REPORT Init Duration: 234.46 ms	Phase: init	Status: error	Error Type: Runtime.ExitError
ReferenceError: exports is not defined in ES module scope
This file is being treated as an ES module because it has a '.js' file extension and '/var/task/package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
    at file:///var/task/api/hello.js:2:23
    at ModuleJob.run (node:internal/modules/esm/module_job:194:25)
INIT_REPORT Init Duration: 278.17 ms	Phase: invoke	Status: error	Error Type: Runtime.ExitError
Error: Runtime exited with error: exit status 1
Runtime.ExitError

so, a tsconfig.json in /api is required: vercel/vercel#10317 (comment)

Finally, a Hello World of Vercel Node.js serverless works.

Type of Change

  • New Example
  • Example updates (Bug fixes, new features, etc.)
  • Other (changes to the codebase, but not to examples)

Copy link

vercel bot commented Nov 28, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
app-dir-css-in-js ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 10, 2023 7:16pm
app-dir-i18n ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 10, 2023 7:16pm
app-dir-share-state ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 10, 2023 7:16pm
edge-api-routes-cache-control ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 10, 2023 7:16pm
edge-api-routes-hello-world ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 10, 2023 7:16pm
edge-api-routes-json-response ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 10, 2023 7:16pm
edge-api-routes-query-parameters ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 10, 2023 7:16pm
edge-functions-authed-proxy ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 10, 2023 7:16pm
edge-functions-cookies ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 10, 2023 7:16pm
edge-functions-news ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 10, 2023 7:16pm
edge-functions-streams ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 10, 2023 7:16pm
edge-geolocation-country-block ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 10, 2023 7:16pm
edge-middleware-modify-request-header ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 10, 2023 7:16pm
edge-user-agent-based-rendering ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 10, 2023 7:16pm
example-auth-with-ory ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 10, 2023 7:16pm
example-reduce-image-bandwidth-usage ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 10, 2023 7:16pm
examples ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 10, 2023 7:16pm
geolocation-script ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 10, 2023 7:16pm
i18n ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 10, 2023 7:16pm
next-edge-api-route-hello-world ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 10, 2023 7:16pm
next-flask ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 10, 2023 7:16pm
nodejs-api ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 10, 2023 7:16pm
redirect-with-fallback ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 10, 2023 7:16pm
solutions-combining-data-fetching-strategies ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 10, 2023 7:16pm
solutions-image-fallback ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 10, 2023 7:16pm
solutions-image-offset ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 10, 2023 7:16pm
solutions-loading-web-fonts ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 10, 2023 7:16pm
solutions-microfrontends ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 10, 2023 7:16pm
solutions-microfrontends-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 10, 2023 7:16pm
solutions-pagination-with-ssg ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 10, 2023 7:16pm
solutions-reuse-responses ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 10, 2023 7:16pm
solutions-script-component-ad ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 10, 2023 7:16pm
solutions-script-component-strategies ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 10, 2023 7:16pm
solutions-testing ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 10, 2023 7:16pm
wasm-rust-hello-world ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 10, 2023 7:16pm
wasm-rust-xor ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 10, 2023 7:16pm

Copy link

vercel bot commented Nov 28, 2023

@TechQuery is attempting to deploy a commit to the Vercel Examples Team on Vercel.

A member of the Team first needs to authorize it.

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 this pull request may close these issues.

None yet

1 participant