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

wrangler pages dev crashes if tsconfig.json exists in /functions #75

Closed
drevantonder opened this issue Dec 5, 2021 · 0 comments · Fixed by #216
Closed

wrangler pages dev crashes if tsconfig.json exists in /functions #75

drevantonder opened this issue Dec 5, 2021 · 0 comments · Fixed by #216
Labels
pages Relating to Pages

Comments

@drevantonder
Copy link

Having a tsconfig.json file in the /functions folder causes wrangler pages dev to crash.

Looking at the error output, wrangler is trying to compile tsconfig.json with esbuild which fails and then crashes wrangler.

Environment Information

  • Node.js v16.10.0
  • NPM v7.24.0
  • OS: Ubuntu 20.04.3 (running on Windows 11 via WSL)

Steps to reproduce

  • Create a new Cloudflare Pages compatible project with TS. E.g. Vite with vue-ts: npm init vite@latest foo -- --template vue-ts
  • Install npm packages cd foo && npm i
  • Create a functions directory and add a test function:

/functions/api/test.ts:

// Uses the example code from https://developers.cloudflare.com/pages/platform/functions#writing-your-first-function

export async function onRequest(context) {
  // Contents of context object
  const {
    request, // same as existing Worker API
    env, // same as existing Worker API
    params, // if filename includes [id] or [[path]]
    waitUntil, // same as ctx.waitUntil in existing Worker API
    next, // used for middleware or to fetch assets
    data, // arbitrary space for passing data between middlewares
  } = context;

  return new Response("Hello, world!");
}
  • Run with wrangler npx wrangler pages dev -- npm run dev. Works ✅
  • Add a tsconfig.json file in /functions.

/functions/tsconfig.json:

{
  "compilerOptions": {
    "target": "ES2020",
    "module": "CommonJS",
    "lib": ["ES2020"],
    "types": ["@cloudflare/workers-types"]
  }
}
  • Run with wrangler npx wrangler pages dev -- npm run dev. Fails ❌

Error output:

Running npm run dev...
Sleeping 5 seconds to allow proxy process to start before attempting to automatically determine port...
To skip, specify the proxy port with --proxy.
[proxy]: 
> [email protected] dev
> vite


[proxy]: Pre-bundling dependencies:
  vue

[proxy]: (this will be run only when your dependencies or config have changed)

[proxy]: 
  vite v2.6.14 dev server running at:


[proxy]:   > Local: http://localhost:3000/
  > Network: use `--host` to expose

  ready in 394ms.


Automatically determined the proxy port to be 3000.
/home/drevan/projects/foo/node_modules/@cloudflare/pages-functions-compiler/node_modules/esbuild/lib/main.js:1493
  let error = new Error(`${text}${summary}`);
              ^

Error: Transform failed with 1 error:
<stdin>:2:19: error: Expected ";" but found ":"
    at failureErrorWithLog (/home/drevan/projects/foo/node_modules/@cloudflare/pages-functions-compiler/node_modules/esbuild/lib/main.js:1493:15)
    at /home/drevan/projects/foo/node_modules/@cloudflare/pages-functions-compiler/node_modules/esbuild/lib/main.js:1282:29
    at /home/drevan/projects/foo/node_modules/@cloudflare/pages-functions-compiler/node_modules/esbuild/lib/main.js:629:9
    at handleIncomingPacket (/home/drevan/projects/foo/node_modules/@cloudflare/pages-functions-compiler/node_modules/esbuild/lib/main.js:726:9)
    at Socket.readFromStdout (/home/drevan/projects/foo/node_modules/@cloudflare/pages-functions-compiler/node_modules/esbuild/lib/main.js:596:7)
    at Socket.emit (node:events:390:28)
    at addChunk (node:internal/streams/readable:315:12)
    at readableAddChunk (node:internal/streams/readable:289:9)
    at Socket.Readable.push (node:internal/streams/readable:228:10)
    at Pipe.onStreamRead (node:internal/stream_base_commons:199:23) {
  errors: [
    {
      detail: undefined,
      location: {
        column: 19,
        file: '<stdin>',
        length: 1,
        line: 2,
        lineText: '  "compilerOptions": {',
        namespace: '',
        suggestion: ''
      },
      notes: [],
      pluginName: '',
      text: 'Expected ";" but found ":"'
    }
  ],
  warnings: []
}
/home/drevan/projects/foo/node_modules/wrangler/wrangler-dist/cli.js:27069
            throw ex;
            ^

BuildError [1]: Build failed with exit code 1
    at ChildProcess.<anonymous> (file:///home/drevan/projects/foo/node_modules/@miniflare/core/dist/src/index.js:214:25)
    at ChildProcess.emit (node:events:390:28)
    at Process.ChildProcess._handle.onexit (node:internal/child_process:290:12) {
  code: 1,
  cause: undefined
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pages Relating to Pages
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants