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

Deno doesn't define "Buffer" breaking example docs template in SSR preview #5194

Closed
1 task done
antonymott opened this issue Oct 26, 2022 · 1 comment
Closed
1 task done

Comments

@antonymott
Copy link
Contributor

What version of astro are you using?

1.5.2

Are you using an SSR adapter? If so, which one?

Deno

What package manager are you using?

pnpm

What operating system are you using?

Linux

Describe the Bug

To reproduce:
pnpm create astro@latest -- --template docs
pnpm astro add deno
pnpm build
pnpm preview

Server does run on port 8085, but avatars are missing from footer and log shows error:
[error] /src/components/AvatarList.astro
Buffer is not defined

If it helps, the following info/notice gets logged during "pnpm build" but I think that is not related:
building client
transforming (115) node_modules/.pnpm/@algolia[email protected]/node_mod'default' is not exported by 'node_modules/.pnpm/@[email protected]_ozja46d2hdfcawewer6noq2pdi/node_modules/@docsearch/react/dist/esm/index.js'
'default' is not exported by 'node_modules/.pnpm/@[email protected]_ozja46d2hdfcawewer6noq2pdi/node_modules/@docsearch/react/dist/esm/index.js'

A similar issue was solved #4323, and node's Buffer incompatibility with Deno is discussed with various suggested fixes
in this medium article

I was able to fix this in production mode - showing the Avatars with no error - with an import in the frontmatter:

import { Buffer } from "https://deno.land/std/io/buffer.ts";

and rewriting the node.js style "Buffer" to a deno style "Buffer":

// const auth = `Basic ${Buffer.from(token, "binary").toString("base64")}`;
const auth_ = new Buffer(token, "binary").toString("base64");
const auth = `Basic ${auth_}`;

Even with the VS deno code extension enabled in the Astro workspace, the deno import caused the linter to complain:
"An import path cannot end with a '.ts' extension. Consider importing 'https://deno.land/std/io/buffer.js' instead.ts(2691)"

But more important the fix in production mode caused Astro dev mode to break, so perhaps Astro dev server doesn't like using the Deno Buffer?

I thought of using a ternary operator to check the environment if Astro is in dev or production mode, and make a conditional import, but that seemed a bit of a kluge.

Happy to do the PR if the way above is generally OK.

Link to Minimal Reproducible Example

https://codesandbox.io/s/github/withastro/astro/tree/latest/examples/docs

Participation

  • I am willing to submit a pull request for this issue.
@matthewp
Copy link
Contributor

That wouldn't work. Perhaps the Deno adapter can import the Buffer and set it as a global? That's the only solution I can forsee.

We don't intend to make every example compatible with every production runtime though. That would be impossible as many Node packages only work in Node. Going to close the issue for that reason, but if you come up with something please do submit a PR. Thanks!

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

No branches or pull requests

2 participants