-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
v0.35.0 TSX file can't be compiled #4197
Comments
If you change the file ext to |
@tamoore Thank you. But I found the way. By official guide, triple-slash reference to type definition is needed for /// <reference path="path/to/react.d.ts" />
import React from "https://dev.jspm.io/react"
export default () => <html>deno</html>; I'm using patched react // @deno-types="../../../../types/react/index.d.ts"
export * from "https://dev.jspm.io/react@16.10.2/index.js"; If indirect cause of the problem is |
This also works and seems to be the correct way. import React from "https://dev.jspm.io/react"
import { FC } from "path/to/react.d.ts"
export default (() => <html>deno</html>) as FC; |
It is a combination of things, #4040 which stopped analysing JavaScript imports as well as forcing strict mode. This should work: // @deno-types="../../../../types/react/index.d.ts"
export * from "https://dev.jspm.io/react@16.10.2/index.js"; The path references should also work, though we don't have tests for their resolution, so they might not work the way the work on I will look into why we broke that, as that certainly wasn't intended. What is the ultimate use case here? As the runtime compiler APIs are in place and if you are trying to generate something that you run in a browser, that might be better suited. I still have work to do before landing it in standard, but take a look at this: https://github.com/kitsonk/deno/blob/std-react/std/build/react.ts The following code works, with no "magical" things: const [diagnostics, output] = await Deno.compile(
"./std/build/examples/react-index.jsx",
undefined,
{
allowJs: true,
checkJs: true,
lib: ["dom", "es2018"],
sourceMap: false,
target: "es2018",
types: ["./std/build/types/react.d.ts", "./std/build/types/react-dom.d.ts"]
}
); And builds the following example to JS: class Square extends React.Component {
render() {
return <button className="square">{/* TODO */}</button>;
}
}
class Board extends React.Component {
/**
* @param {number} i
*/
renderSquare(i) {
return <Square />;
}
render() {
const status = "Next player: X";
return (
<div>
<div className="status">{status}</div>
<div className="board-row">
{this.renderSquare(0)}
{this.renderSquare(1)}
{this.renderSquare(2)}
</div>
<div className="board-row">
{this.renderSquare(3)}
{this.renderSquare(4)}
{this.renderSquare(5)}
</div>
<div className="board-row">
{this.renderSquare(6)}
{this.renderSquare(7)}
{this.renderSquare(8)}
</div>
</div>
);
}
}
class Game extends React.Component {
render() {
return (
<div className="game">
<div className="game-board">
<Board />
</div>
<div className="game-info">
<div>{/* status */}</div>
<ol>{/* TODO */}</ol>
</div>
</div>
);
}
}
// ========================================
ReactDOM.render(<Game />, document.getElementById("root")); |
Regarding use cases, I use JSX for server-side rendering of HTML, not for bundling or use in a browser. It's awesome that Deno supports it out of the box with zero configuration. Unfortunately, even a Hello World with JSX does not work anymore when used in a TypeScript file. |
Ok, I am pretty sure that I understand how it broke. With @sholladay do you use the Deno default of |
Yes, I'm not using any config. But also worth mentioning that I'm planning to use JSX in some reusable modules. Those projects obviously won't have control over the config used by the end-user. |
@sholladay how are you making the |
Similar to the OP, I import React from the jspm CDN. import React from 'https://dev.jspm.io/react@16.12.0'; The JSX, such as In the future, I will likely also try to use JSX for command line apps. Just need to make something like Ink for Deno. |
The "problem" here is that we turned on Given Deno, there are three possible solutions here I can see:
// @deno-types=https://deno.land/std/react/react.d.ts
import React from "https://dev.jspm.io/react@16.12.0";
The first two options are likely the best options. Baking more stuff into Deno, especially stuff that might conflict with other use cases, doesn't make sense to me. I've got a set of types based of |
Those thoughts all sound reasonable to me. That said, I guess I don't really see the point of supporting JSX out of the box if it doesn't actually work. (That is, work under TypeScript, which is the norm for Deno.) Maybe |
The problem is JSX doesn't work out of the box anywhere. You always needs something to interpret it. Going with JSX preserve is totally useless in Deno, because it would emit code that just doesn't run. Therefore we default to So the fact that JSX is useless in Deno without some sort of external library, means that we should get the needed types from that library. That means doing a So other we get more stronger opinionated ways of using JSX under Deno, or we just try to make it easier. The worry about that though is whatever opinions we have would mean it would be more difficult for someone to do something else if they didn't like those opinions. |
Could If not, I think my vote would be to include the JSX types globally. While it's opinionated, it's better than being broken. |
Oooh, that is a good idea. In theory, it should be possible. |
Do we have an issue yet for providing the URL of the types via an HTTP header, so the compiler hint isn't necessary? |
Now we do. |
I found it difficult to find the right imports and types to remove this error so // main.tsx
// @deno-types="https://deno.land/x/types/react/v16.13.1/react.d.ts"
import React from "https://cdn.pika.dev/@pika/react@v16.13.1";
// @deno-types="https://deno.land/x/types/react-dom/v16.13.1/react-dom.d.ts"
import ReactDOM from "https://cdn.pika.dev/@pika/react-dom@v16.13.1";
// @deno-types="https://deno.land/x/types/react-dom/v16.13.1/server.d.ts"
import ReactDOMServer from "https://dev.jspm.io/react-dom@16.13.1/server.js";
const str: string = ReactDOMServer.renderToString(<div className="deno">land</div>);
console.log(str);
|
@bardiarastin #5726 is published on deno v1.0.2 // main.tsx
// @deno-types="https://deno.land/x/types/react/v16.13.1/react.d.ts"
import React from "https://cdn.pika.dev/@pika/react@v16.13.1";
// @deno-types="https://deno.land/x/types/react-dom/v16.13.1/react-dom.d.ts"
import ReactDOM from "https://cdn.pika.dev/@pika/react-dom@v16.13.1";
// @deno-types="https://deno.land/x/types/react-dom/v16.13.1/server.d.ts"
import ReactDOMServer from "https://dev.jspm.io/react-dom@16.13.1/server.js";
const str: string = ReactDOMServer.renderToString(<div className="deno">land</div>);
console.log(str); $ deno --version
deno 1.0.2
v8 8.4.300
typescript 3.9.2
$ deno run main.tsx
Compile file:///Users/xcatliu/work/test/main.tsx
error: TS2307 [ERROR]: Cannot find module 'https://cdn.pika.dev/@pika/react@v16.13.1' or its corresponding type declarations.
import React from 'https://cdn.pika.dev/@pika/react@v16.13.1';
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
at file:///Users/xcatliu/work/test/main.tsx:4:19
TS2307 [ERROR]: Cannot find module 'https://cdn.pika.dev/@pika/react-dom@v16.13.1' or its corresponding type declarations.
import ReactDOM from 'https://cdn.pika.dev/@pika/react-dom@v16.13.1';
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
at file:///Users/xcatliu/work/test/main.tsx:7:22
TS2307 [ERROR]: Cannot find module 'https://dev.jspm.io/react-dom@16.13.1/server.js' or its corresponding type declarations.
import ReactDOMServer from 'https://dev.jspm.io/react-dom@16.13.1/server.js';
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
at file:///Users/xcatliu/work/test/main.tsx:10:28
TS7026 [ERROR]: JSX element implicitly has type 'any' because no interface 'JSX.IntrinsicElements' exists.
const str: string = ReactDOMServer.renderToString(<div className="deno">land</div>);
~~~~~~~~~~~~~~~~~~~~~~
at file:///Users/xcatliu/work/test/main.tsx:12:51
TS7026 [ERROR]: JSX element implicitly has type 'any' because no interface 'JSX.IntrinsicElements' exists.
const str: string = ReactDOMServer.renderToString(<div className="deno">land</div>);
~~~~~~
at file:///Users/xcatliu/work/test/main.tsx:12:77
Found 5 errors. |
Fixed in Deno v1.0.3 |
index.tsx
I know recently
strict
option enabled by default for deno compiler but I couldn't right way to define correctJSX
namespace for external resources.The text was updated successfully, but these errors were encountered: