Giter VIP home page Giter VIP logo

netlify-wasm-runtime's Introduction

This is a Next.js project bootstrapped with create-next-app.

This project is aimed to demonstrate how to implement a Serverless Functions working with Webassembly in Netlify. The main branch showcases an image processing function, and the tensorflow branch showcases an AI inference function. Both written in simple Rust and runs in the WasmEdge runtime for WebAssembly.

Overview

The Serverless Functions endpoint is located at api/hello.js to meet the requirement of Netlify, but not to the Next.js. So if you want to develop on you local machine, you should put it into pages/api/ and make some change.

The only function in api/hello.js is grayscaling an image. It receives a png file and pass it as stdin stream to a spawned child process. The child process runs using the WasmEdge command.

File api/functions/image-grayscale/src/main.rs implements the grayscaling logic. You can build it with the Rust cargo command with the -target wasm32-wasi option to get the grayscale.wasm file.

We define custom build in api/pre.sh which is called in package.json to download the WasmEdge command.

Learn More

To learn more about Next.js, take a look at the following resources:

To learn more about Serverless Functions in Netlify, take a look at the following resources:

Deploy on Netlify

The easiest way to deploy your Next.js app is to use the Netlify Platform.

Check out our Next.js deployment documentation for more details.

netlify-wasm-runtime's People

Contributors

juntao avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

netlify-wasm-runtime's Issues

error while trying to deploy the main/tensorflow branch in netlify edge function

I have cloned this repo netlify-wasm-runtime (with tensorflow branch) and deployed to netlify as edge function without any modification. however, the build process is failed. please help!

11:08:14 PM: Netlify Build
11:08:14 PM: ────────────────────────────────────────────────────────────────
11:08:14 PM: ​
11:08:14 PM: ❯ Version
11:08:14 PM: @netlify/build 29.36.0
11:08:14 PM: ​
11:08:14 PM: ❯ Flags
11:08:14 PM: baseRelDir: true
11:08:14 PM: buildId: 65da06420ae7ed07f99d9bd2
11:08:14 PM: deployId: 65da06420ae7ed07f99d9bd4
11:08:14 PM: ​
11:08:14 PM: ❯ Current directory
11:08:14 PM: /opt/build/repo
11:08:14 PM: ​
11:08:14 PM: ❯ Config file
11:08:14 PM: /opt/build/repo/netlify.toml
11:08:14 PM: ​
11:08:14 PM: ❯ Context
11:08:14 PM: production
11:08:14 PM: ​
11:08:14 PM: ❯ Installing plugins
11:08:14 PM: - @netlify/[email protected]
11:08:28 PM: ​
11:08:28 PM: ❯ Using Next.js Runtime - v4.41.3
11:08:30 PM: ​
11:08:30 PM: @netlify/plugin-nextjs (onPreBuild event)
11:08:30 PM: ────────────────────────────────────────────────────────────────
11:08:30 PM: ​
11:08:30 PM: No Next.js cache to restore.
11:08:30 PM: ​
11:08:30 PM: (@netlify/plugin-nextjs onPreBuild completed in 92ms)
11:08:30 PM: ​
11:08:30 PM: Build command from Netlify app
11:08:30 PM: ────────────────────────────────────────────────────────────────
11:08:30 PM: ​
11:08:30 PM: $ yarn run build
11:08:30 PM: yarn run v1.22.19
11:08:30 PM: $ next build && cd api && ./pre.sh
11:08:30 PM: Browserslist: caniuse-lite is outdated. Please run:
11:08:30 PM: npx browserslist@latest --update-db
11:08:30 PM: Why you should do it regularly:
11:08:30 PM: https://github.com/browserslist/browserslist#browsers-data-updating
11:08:30 PM: node:internal/errors:496
11:08:30 PM: ErrorCaptureStackTrace(err);
11:08:30 PM: ^
11:08:30 PM: Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath "./lib/parser" is not defined by "exports" in /opt/build/repo/node_modules/next/node_modules/postcss/package.json
11:08:30 PM: at new NodeError (node:internal/errors:405:5)
11:08:30 PM: at exportsNotFound (node:internal/modules/esm/resolve:366:10)
11:08:30 PM: at packageExportsResolve (node:internal/modules/esm/resolve:713:9)
11:08:30 PM: at resolveExports (node:internal/modules/cjs/loader:584:36)
11:08:30 PM: at Module._findPath (node:internal/modules/cjs/loader:658:31)
11:08:30 PM: at Module._resolveFilename (node:internal/modules/cjs/loader:1120:27)
11:08:30 PM: at Module._load (node:internal/modules/cjs/loader:975:27)
11:08:30 PM: at Module.require (node:internal/modules/cjs/loader:1225:19)
11:08:30 PM: at require (node:internal/modules/helpers:177:18)
11:08:30 PM: at 552 (/opt/build/repo/node_modules/next/dist/compiled/postcss-scss/scss-syntax.js:1:11590)
11:08:30 PM: at nccwpck_require (/opt/build/repo/node_modules/next/dist/compiled/postcss-scss/scss-syntax.js:1:11735)
11:08:30 PM: at 270 (/opt/build/repo/node_modules/next/dist/compiled/postcss-scss/scss-syntax.js:1:400)
11:08:30 PM: at nccwpck_require (/opt/build/repo/node_modules/next/dist/compiled/postcss-scss/scss-syntax.js:1:11735)
11:08:30 PM: at 327 (/opt/build/repo/node_modules/next/dist/compiled/postcss-scss/scss-syntax.js:1:260)
11:08:30 PM: at nccwpck_require (/opt/build/repo/node_modules/next/dist/compiled/postcss-scss/scss-syntax.js:1:11735)
11:08:30 PM: at 845 (/opt/build/repo/node_modules/next/dist/compiled/postcss-scss/scss-syntax.js:1:3733) {
11:08:30 PM: code: "ERR_PACKAGE_PATH_NOT_EXPORTED"
11:08:30 PM: }
11:08:30 PM: Node.js v18.19.1
11:08:30 PM: error Command failed with exit code 1. (https://ntl.fyi/exit-code-1)
11:08:30 PM: info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
11:08:30 PM: ​
11:08:30 PM: "build.command" failed
11:08:30 PM: ────────────────────────────────────────────────────────────────
11:08:30 PM: ​
11:08:30 PM: Error message
11:08:30 PM: Command failed with exit code 1: yarn run build (https://ntl.fyi/exit-code-1)
11:08:30 PM: ​
11:08:30 PM: Error location
11:08:30 PM: In Build command from Netlify app:
11:08:30 PM: yarn run build
11:08:30 PM: ​
11:08:30 PM: Resolved config
11:08:30 PM: build:
11:08:30 PM: command: yarn run build
11:08:30 PM: commandOrigin: ui
11:08:30 PM: environment:
11:08:30 PM: - NEXT_PRIVATE_TARGET
11:08:30 PM: publish: /opt/build/repo/.next
11:08:30 PM: publishOrigin: ui
11:08:30 PM: functions:
11:08:30 PM: "*":
11:08:30 PM: included_files:
11:08:31 PM: Failed during stage "building site": Build script returned non-zero exit code: 2
11:08:31 PM: - api/**
node_bundler: esbuild
functionsDirectory: /opt/build/repo/api
plugins:
- inputs: {}
origin: ui
package: "@netlify/plugin-nextjs"
11:08:31 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
11:08:31 PM: Failing build: Failed to build site
11:08:31 PM: Finished processing build request in 33.616s

Error: Stream body too big?

I'm getting this error while uploading PNG images. It worked fine with smaller files and it threw errors for files size greater than 3.0 MB

Please note I'm running netlify functions locally.

Error: Stream body too big
    at IncomingMessage.onData (/home/xyz/.asdf/installs/nodejs/16.2.0/.npm/lib/node_modules/netlify-cli/src/utils/create-stream-promise.js:24:16)
    at IncomingMessage.emit (node:events:365:28)
    at IncomingMessage.emit (node:domain:470:12)
    at addChunk (node:internal/streams/readable:314:12)
    at readableAddChunk (node:internal/streams/readable:289:9)
    at IncomingMessage.Readable.push (node:internal/streams/readable:228:10)
    at HTTPParser.parserOnBody (node:_http_common:140:24)
Error: Stream body too big
    at IncomingMessage.onData (/home/xyz/.asdf/installs/nodejs/16.2.0/.npm/lib/node_modules/netlify-cli/src/utils/create-stream-promise.js:24:16)
    at IncomingMessage.emit (node:events:365:28)
    at IncomingMessage.emit (node:domain:470:12)
    at addChunk (node:internal/streams/readable:314:12)
    at readableAddChunk (node:internal/streams/readable:289:9)
    at IncomingMessage.Readable.push (node:internal/streams/readable:228:10)
    at HTTPParser.parserOnBody (node:_http_common:140:24)

/home/xyz/.asdf/installs/nodejs/16.2.0/.npm/lib/node_modules/netlify-cli/node_modules/netlify-redirector/lib/redirects.js:116
      throw ex;
      ^
abort({}) at Error: 
    at jsStackTrace (/home/xyz/.asdf/installs/nodejs/16.2.0/.npm/lib/node_modules/netlify-cli/node_modules/netlify-redirector/lib/redirects.js:1070:13)
    at stackTrace (/home/xyz/.asdf/installs/nodejs/16.2.0/.npm/lib/node_modules/netlify-cli/node_modules/netlify-redirector/lib/redirects.js:1087:12)
    at process.abort (/home/xyz/.asdf/installs/nodejs/16.2.0/.npm/lib/node_modules/netlify-cli/node_modules/netlify-redirector/lib/redirects.js:8502:44)
    at process.emit (node:events:365:28)
    at processEmit [as emit] (/home/xyz/.asdf/installs/nodejs/16.2.0/.npm/lib/node_modules/netlify-cli/node_modules/signal-exit/index.js:175:34)
    at emit (node:internal/process/promises:136:22)
    at processPromiseRejections (node:internal/process/promises:242:25)
    at processTicksAndRejections (node:internal/process/task_queues:97:32)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.