netlify / remix-template

Deploy your Remix site to Netlify
83 stars 27 forks source link

Error while deploying app with Edge Functions #110

Closed adamduncan closed 1 year ago

adamduncan commented 1 year ago

Describe the bug Trying to build and deploy out-of-the-box remix-template to Netlify. No modifications made to template after install. App builds and runs locally with netlify dev without an issue. When running netlify deploy --build, seeing an error regarding excluded_patterns

2. Edge Functions bundling                                    
────────────────────────────────────────────────────────────────

Packaging Edge Functions from .netlify/edge-functions directory:
 - server

  Bundling of edge function failed                              
────────────────────────────────────────────────────────────────

  Error message
  Validation of Edge Functions manifest failed
  FORMAT excluded_patterns needs to be an array of regex that starts with ^ followed by / and ends with $ without any additional slashes before and afterwards

    19 |     "server": {
    20 |       "excluded_patterns": [
  > 21 |         "/_assets/*"
       |         ^^^^^^^^^^^^ 👈🏽  format excluded_patterns needs to be an array of regex that starts with ^ followed by / and ends with $ without any additional slashes before and afterwards
    22 |       ],
    23 |       "cache": "manual",
    24 |       "generator": "internalFunc"

  Error location
  While bundling edge function

  Resolved config
  build:
    command: npm run build
    commandOrigin: config
    publish: /Users/adamduncan/Websites/_examples/netlify-remix-template/public
    publishOrigin: config

To Reproduce Steps to reproduce the behavior:

  1. npx create-remix@latest --template netlify/remix-template
  2. Choose TypeScript
  3. Run npm install
  4. Choose Run your Remix site with: Netlify Edge Functions (beta)
  5. cd into install directory
  6. netlify dev (works fine locally, including use of edge functions if created in /netlify/edge-functions/ dir)
  7. npm run build (succeeds)
  8. netlify deploy --build — fails with above message ☝️

Expected behavior Successful deployment to Netlify

Screenshots

Screenshot 2023-04-04 at 19 26 22

Desktop:

Additional context As suggested, I attempted to set excluded_patterns to:

nickytonline commented 1 year ago

Thanks for reporting this @adamduncan! This was working and was tested so not sure what's up. I'll speak to the team to see if anything changed recently.

nickytonline commented 1 year ago

@adamduncan, I figured out the issue. One, the error is because things did get updated on our end, so

// Import path interpreted by the Remix compiler
import * as build from "@remix-run/dev/server-build";
import { createRequestHandler } from "@netlify/remix-edge-adapter";

export default createRequestHandler({
  build,
  // process.env.NODE_ENV is provided by Remix at compile time
  mode: process.env.NODE_ENV,
});

export const config = {
  cache: "manual",
  path: "/*",
  // Let the CDN handle requests for static assets, i.e. /_assets/*
  //
  // Add other exclusions here, e.g. "/api/*" for custom Netlify functions or
  // custom Netlify Edge Functions
-  excluded_patterns: ["/_assets/*"],
+  excluded_patterns: ["^/_assets/*$"],
};

but also, you'll need to update the app/routes/index.tsx to app/routes/_index.tsx. It's part of the new Remix routing. I have a PR up for it, but I guess it's no longer behind their future flag. See https://github.com/netlify/remix-template/pull/105.

I'll create a PR to update both these things. Thanks again for reporting this!

adamduncan commented 1 year ago

@nickytonline Thanks for following up on this so swiftly! Appreciate the insights 👍

Yep, looks like with that change to excluded_patterns: ["^/_assets/*$"] and the _index.tsx file renaming, things are deploying and functioning as expected: https://netlify-remix-template-test.netlify.app