sholladay / pogo

Server framework for Deno

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

React and JSX support

About7Sharks opened this issue · comments

import React from 'https://dev.jspm.io/react';
// ...
server.router.get('/', () => {
    return <p>Hello, world!</p>;
});

gives me the following error

error TS2304: Cannot find name 'p'.

► file:///Users/sock/code/denoAccubrew/server.ts:16:13

16     return <p>Hello, world!</p>;
               ^

error TS2304: Cannot find name 'Hello'.

► file:///Users/sock/code/denoAccubrew/server.ts:16:15

16     return <p>Hello, world!</p>;
                 ~~~~~

error TS2304: Cannot find name 'world'.

► file:///Users/sock/code/denoAccubrew/server.ts:16:22

16     return <p>Hello, world!</p>;
                        ~~~~~

error TS1161: Unterminated regular expression literal.

► 

Found 4 errors.

I wrapped it in a string and it seems to be working now. If this is the fix i'd update the docs to be correct.

Hmm I cannot reproduce your error and you should definitely not wrap the JSX in a string. But let's try some general debugging.

  1. Make sure your code defines a server and starts it, etc. The // ... in the code example was meant to indicate that this builds on the basic usage example towards the top of the README. However, since that may not have been entirely clear, I just pushed a commit that changes it to a fully fledged and self-contained code example.
  2. Make sure you are using a file extension that compiles JSX, such as .jsx or .tsx. I just pushed a commit that explicitly mentions that. It's a common convention for all React projects, even in Node, but in Deno it is required. I'm guessing this is the problem for you.
  3. Make sure you are using a recent version of Deno. Pogo should work with Deno 0.30 or newer, but I'd recommend 0.33 as that is what the latest version of Pogo is being tested against in CI at the moment. If you have Deno installed via Homebrew, you can update it with brew upgrade deno.
  4. Make sure you are using the latest version of Pogo. If you ever tried Pogo before it had support for React, then Deno cached your download of Pogo and is still using it. You'll need to either use Deno's --reload flag to force it to re-download Pogo or use a URL that includes the version number. For example, instead of import pogo from 'https://deno.land/x/pogo/main.js';, you can use import pogo from 'https://deno.land/x/pogo@v0.3.0/main.js';. I don't have this documented in the README at the moment, because that's how Deno works and it has nothing to do with Pogo itself, but since Deno is so new and we're all still getting used to that, it may be worth adding to the documentation anyway.

Solution 2 Solved it, Thanks!

ELI5: changed server.ts to server.jsx

deno --allow-net server.jsx

Great! Glad that worked. Since you were using .ts previously, it's worth mentioning that you can still use TypeScript, the extension just has to be .tsx.

So, either .jsx or .tsx will work - the latter compiles TypeScript in addition to JSX.