Skip to content

Error on 11-typescript-and-jsx-in-deno #4

Description

@warcayac

I have a Deno 2 project with these files:

deno.json

{
    "compilerOptions": {
        "jsx": "react",
        "jsxFactory": "React.createElement",
        "jsxFragmentFactory": "React.Fragment"
    },
    "imports": {
        "react": "npm:react@^18.3.1"
    }
}

App.tsx

import React from "https://esm.sh/react@18.3.1";

const App = () => {
    return <h1>Hello from JSX</h1>;
};

console.log(App());

this project is running as expected with no errors, But if I use this line:

import React from "react";

I get the following error on H1 tags:

JSX element implicitly has type 'any' because no interface 'JSX.IntrinsicElements' exists.deno-ts(7026)
⚠ Error (TS7026)  | 
JSX element implicitly has type any because no interface JSX.IntrinsicElements exists.

I tried adding @types/react package, then no error was showed however when running the program I get this error:

error: Could not resolve 'npm:@types/react@18.3.12'.

Caused by:
    [ERR_INVALID_PACKAGE_TARGET] Invalid "exports" main target {"types@<=5.0":{"default":"./ts5.0/index.d.ts"},"types":{"default":"./index.d.ts"}} defined in the package config /home/warcayac/.cache/deno/npm/registry.npmjs.org/@types/react/18.3.12/package.json imported from 'file:///home/warcayac/DataDisk/Projects/Programming/Deno/_tutorials/MoonHighway/deno-2-course/11-typescript-and-jsx-in-deno/App.tsx'; target must start with "./"

I don't know what's happening. Any ideas?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions