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

[Bug]TypeError: preact_render_to_string_1.renderToString is not a function #197

Open
strrchr opened this issue Apr 29, 2021 · 5 comments
Open

Comments

@strrchr
Copy link

strrchr commented Apr 29, 2021

When using ts-node.

@marvinhagemeister
Copy link
Member

Please post your tsconfig.json if one is present in your project and how you're importing preact-render-to-string. We don't see what's on your screen so we need a little more information ;)

I've been using ts-node with preact-render-to-string myself in quite a few projects without issues. So I'm guessing there either is a combination of a configuration error in tsconfig.json and the way preact-render-to-string is imported.

@pavel-klimov
Copy link

I have same problem with default nest.js project. It have that tsconfig.json:

{
  "compilerOptions": {
    "module": "commonjs",
    "declaration": true,
    "removeComments": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "allowSyntheticDefaultImports": true,
    "target": "es2017",
    "sourceMap": true,
    "outDir": "./dist",
    "baseUrl": "./",
    "incremental": true
  }
}

@lemonmade
Copy link
Contributor

I think this has to do with the way the non-ESM version of this package is published. That version ends up only exporting the "default" export from the library (https://cdn.jsdelivr.net/npm/preact-render-to-string@5.1.20/dist/index.js), which excludes all the additional named exports. You can see the problem in the Node REPL for a project with type: "module" that depends on preact-render-to-string:

Screen Shot 2022-03-23 at 6 07 50 PM

@marvinhagemeister
Copy link
Member

This makes a strong argument in favor of removing the default export all together. With only named exports we'd ensure that our lib can be used the same way across module systems and avoid the issues surrounding default exports in different module systems entirely.

@toverux
Copy link

toverux commented Aug 18, 2022

Stumbled upon this too.
Had to use the default import and not the named variant.

This makes a strong argument in favor of removing the default export all together.

Yes, default imports are also not very liked today, and unpractical to use. Some consider it as being a bad practice. I think they only make perfect sense when importing non-JS things/unstructured data with module bundlers, otherwise they probably should be avoided as it's mostly detrimental to DX (when it doesn't causes problems with non-ESM environments, like here).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants