Giter Club home page Giter Club logo

Comments (6)

Cherry avatar Cherry commented on July 22, 2024

The equivalent code with module workers would look like this:

import { getAssetFromKV, NotFoundError, MethodNotAllowedError } from '@cloudflare/kv-asset-handler'
import manifestJSON from '__STATIC_CONTENT_MANIFEST'
const assetManifest = JSON.parse(manifestJSON)

export default {
	async fetch(request, env, ctx) {
		const response = await getAssetFromKV({
			request,
			waitUntil(promise) {
				return ctx.waitUntil(promise)
			},
		},
		{
			ASSET_NAMESPACE: env.__STATIC_CONTENT,
			ASSET_MANIFEST: assetManifest,
		});
		return response;
	},
}

It's a bit more verbose given the age of this module and being designed for older standards, but that's how I'm using it in production in various projects today.

from kv-asset-handler.

mrbm avatar mrbm commented on July 22, 2024

Hi @Cherry thanks for the response

I dropped in the code, but I'm getting a bug on:
import manifestJSON from '__STATIC_CONTENT_MANIFEST'
Here are the error logs, might you have a suggestion? Thanks!

ERROR in ./index.js 2:0-52
Module not found: Error: Can't resolve '__STATIC_CONTENT_MANIFEST' in '/github/workspace'
resolve '__STATIC_CONTENT_MANIFEST' in '/github/workspace'
  Parsed request is a module
  using description file: /github/workspace/package.json (relative path: .)
    Field 'browser' doesn't contain a valid alias configuration
    resolve as module
      looking for modules in /github/workspace/node_modules
        single file module
          using description file: /github/workspace/package.json (relative path: ./node_modules/__STATIC_CONTENT_MANIFEST)
            no extension
              Field 'browser' doesn't contain a valid alias configuration
              /github/workspace/node_modules/__STATIC_CONTENT_MANIFEST doesn't exist
            .js
              Field 'browser' doesn't contain a valid alias configuration
              /github/workspace/node_modules/__STATIC_CONTENT_MANIFEST.js doesn't exist
            .json
              Field 'browser' doesn't contain a valid alias configuration
              /github/workspace/node_modules/__STATIC_CONTENT_MANIFEST.json doesn't exist
            .wasm
              Field 'browser' doesn't contain a valid alias configuration
              /github/workspace/node_modules/__STATIC_CONTENT_MANIFEST.wasm doesn't exist
        /github/workspace/node_modules/__STATIC_CONTENT_MANIFEST doesn't exist
      /github/node_modules doesn't exist or is not a directory
      /node_modules doesn't exist or is not a directory

webpack 5.75.0 compiled with 1 error in 11783 ms

✘ [ERROR] Command failed with exit code 1: npm run build

from kv-asset-handler.

Cherry avatar Cherry commented on July 22, 2024

Can you share a minimal reproduction? My example works with wrangler and its built-in bundler (esbuild). If you're using another bundler like webpack (as it looks like you are in your build logs), you will need to mark the dependency as "external".

from kv-asset-handler.

mrbm avatar mrbm commented on July 22, 2024

Quick question, do I need to create a actual file called
__STATIC_CONTENT_MANIFEST

that has some parameters in it?

from kv-asset-handler.

Cherry avatar Cherry commented on July 22, 2024

No. That "file" is handled and uploaded by wrangler when you publish the worker. You just need to make sure it's marked as "external" if you're using a custom bundler like webpack.

from kv-asset-handler.

Cherry avatar Cherry commented on July 22, 2024

This is falling out of scope for this repository, but you should be able to completely nuke that file and use just a standard wrangler2 build, with node_compat. I'd recommend joining the Cloudflare Discord and asking this there.

from kv-asset-handler.

Related Issues (20)

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.