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

docs: browser CDN example #1032

Merged
merged 4 commits into from
Feb 24, 2022
Merged

docs: browser CDN example #1032

merged 4 commits into from
Feb 24, 2022

Conversation

alanshaw
Copy link
Member

@alanshaw alanshaw commented Feb 23, 2022

Adds an example showing how to load the Web3.Storage client from a CDN in a browser.

Had to swap out the parse-link-header module because it uses Node.js globals (process) and pulls in a bunch of unnecessary deps.

Copy link
Contributor

@vasco-santos vasco-santos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Really liked your terminal alike ❤️

image

Copy link
Contributor

@vasco-santos vasco-santos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh no, client tests are complaining 👀

@alanshaw
Copy link
Member Author

Really liked your terminal alike ❤️

I think that was @olizilla -> I basically copied it from https://github.com/web3-storage/web3.storage/tree/main/packages/client/examples/browser/vite but changed the import path!

@alanshaw
Copy link
Member Author

Oh no, client tests are complaining 👀

I think unrelated, broken in main also: #1034

@alanshaw
Copy link
Member Author

lol, looks like Node.js v16.14.0 broke this.

@alanshaw alanshaw mentioned this pull request Feb 24, 2022
alanshaw pushed a commit that referenced this pull request Feb 24, 2022
Node.js v16.14.0 included [a fix](nodejs/node#40706) that meant that `@web-std/blob` started using the Node.js native version.

Bad news, Node.js currently copies the buffer on every iteration when obtaining a stream from `File.stream()`. It also has a fixed and small chunk size of `65536` bytes. This makes reading the stream VERY slow and this test fails because it times out.

I opened an issue about this here: nodejs/node#42108

Once the test was fixed, the cloudflare build for the website started failing so I had to update next.js to v12. WTF!?!

After that, the client build started failing with:

```
Error: Build failed with 2 errors:
../../node_modules/parse-link-header/index.js:3:17: error: Could not resolve "querystring" (use "platform: 'node'" when building for node)
../../node_modules/parse-link-header/index.js:4:18: error: Could not resolve "url" (use "platform: 'node'" when building for node)
    at failureErrorWithLog (/Users/alan/Code/web3-storage/web3.storage/node_modules/esbuild/lib/main.js:1493:15)
    at /Users/alan/Code/web3-storage/web3.storage/node_modules/esbuild/lib/main.js:1151:28
    at runOnEndCallbacks (/Users/alan/Code/web3-storage/web3.storage/node_modules/esbuild/lib/main.js:941:63)
    at buildResponseToResult (/Users/alan/Code/web3-storage/web3.storage/node_modules/esbuild/lib/main.js:1149:7)
    at /Users/alan/Code/web3-storage/web3.storage/node_modules/esbuild/lib/main.js:1258:14
    at /Users/alan/Code/web3-storage/web3.storage/node_modules/esbuild/lib/main.js:629:9
    at handleIncomingPacket (/Users/alan/Code/web3-storage/web3.storage/node_modules/esbuild/lib/main.js:726:9)
    at Socket.readFromStdout (/Users/alan/Code/web3-storage/web3.storage/node_modules/esbuild/lib/main.js:596:7)
    at Socket.emit (node:events:520:28)
    at addChunk (node:internal/streams/readable:315:12) {
  errors: [
    {
      detail: undefined,
      location: [Object],
      notes: [],
      pluginName: '',
      text: `Could not resolve "querystring" (use "platform: 'node'" when building for node)`
    },
    {
      detail: undefined,
      location: [Object],
      notes: [],
      pluginName: '',
      text: `Could not resolve "url" (use "platform: 'node'" when building for node)`
    }
  ],
  warnings: []
}
```
So I had to roll the update to `parse-link-header` from #1032 into here as well.
@alanshaw alanshaw merged commit 54bd4e3 into main Feb 24, 2022
@alanshaw alanshaw deleted the docs/browser-cdn-example branch February 24, 2022 16:00
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

Successfully merging this pull request may close these issues.

2 participants