wmr icon indicating copy to clipboard operation
wmr copied to clipboard

Typescript is not compiled

Open Aloento opened this issue 3 years ago • 7 comments

Describe the bug yarn create wmr rename public\index.js to public\index.tsx

- export async function prerender(data) {
+ export async function prerender(data: JSX.IntrinsicAttributes) {
	return await ssr(<App {...data} />);
}

then:

500 ./public\index.js - Unexpected token (./index.js:27:37)

  25 | hydrate(<App />);
  26 |
> 27 | export async function prerender(data: JSX.IntrinsicAttributes) {
     |                                     ^
  28 |   return await ssr(<App {...data} />);
  29 | }

Bug occurs with:

  • [x] wmr or wmr start (development)
  • [x] wmr serve
  • [x] wmr build (production)

Desktop (please complete the following information):

  • Node Version: 17
  • WMR Version: newest

Additional context Does this mean we need to enable @rollup/plugin-typescript ourselves?

Aloento avatar Apr 11 '22 23:04 Aloento

You haven't updated the path in your HTML file.

<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="utf-8" />
		<title>WMR App</title>
		<meta name="description" content="WMR App" />
		<meta name="viewport" content="width=device-width,initial-scale=1" />
		<link rel="icon" href="data:" />
-		<link rel="modulepreload" as="script" href="/index.js" />
+		<link rel="modulepreload" as="script" href="/index.tsx" />
		<link rel="stylesheet" href="/style.css" />
	</head>
	<body>
-		<script type="module" src="/index.js"></script>
+		<script type="module" src="/index.tsx"></script>
	</body>
</html>

I imagine this is a symptom of TS's wonky file resolution, in that you can use import ... from 'Foo.js' when Foo.ts is what actually exists on the file system.

rschristian avatar Apr 11 '22 23:04 rschristian

Thank you!!! And maybe mentioned this in your document.

Aloento avatar Apr 11 '22 23:04 Aloento

Building would cause an error as the script source cannot be found. I think I can probably port that over to dev.

rschristian avatar Apr 11 '22 23:04 rschristian

Oh and there's another bug. typescript-paths not working.

In tsconfig.json

"compilerOptions": {
    "paths": {
      "@/*": ["./*"]
    },
  },

then Invalid specifier: @/something

Aloento avatar Apr 11 '22 23:04 Aloento

Not a bug, just a feature that hasn't yet been released. #875 has been merged in, though.

Use aliases in your wmr.config instead. https://wmr.dev/docs/configuration#aliasing-and-path-mappings

rschristian avatar Apr 11 '22 23:04 rschristian

Not a bug, just a feature that hasn't yet been released. #875 has been merged in, though.

Use aliases in your wmr.config instead. https://wmr.dev/docs/configuration#aliasing-and-path-mappings

One problem with this method is that it does not fill in the filename and extension name.

For example: We have /App/index.tsx Then use it as import App from "/App" After compile: import App from "/App/index.js" Everything is fine.

But if I use aliases like import App from "@/App" Then, after compiling: import App from "/App" It's the wrong path.

Aloento avatar Apr 12 '22 14:04 Aloento

Interesting. @ does have some special meaning, so that could present an issue, but I'm also having an issue with using ~ which is in our docs. I'll look into this soon, thanks for bringing it up.

rschristian avatar Apr 12 '22 22:04 rschristian