[Bug]: no redirect rules processed on Netlify build
edmeehan opened this issue · 4 comments
Summary
I have added the gatsby-plugin-netlify
plugin to my gatsby project, and am using the createRedirect
action to add my redirects. The build is creating a _redriects file in the public folder as expected and formatted as expected, but my netlify builds are not recognizing the file. Also the plugin is creating a _headers file, which netlify does recognize and apply during the build.
Something to note, if I copy and paste the _redirects file from my public folder into my static folder, netlify will recognize the redirects and apply them as expected. Also something to note, was I attempted to use node fs package to write my own _redirects file and was running into the exact same problem. Almost feels like a race condition in the build cycle.is
Steps to reproduce
- install plugin
- add plugin to gatsby config file
- add createRedirect actions to gatsby node file on export.createPages
- run local build
- successfully creating _headers & _redirects file
- push code to netlify service
- netlify build does not recognize any redirect rules
A link to a reproduction repository
No response
Plugin version
4.4.0
More information about your build
- I am building using the CLI
- I am building using file-based configuration (
netlify.toml
)
What OS are you using?
Mac OS
Your netlify.toml file
No response
Configuration
`gatsby-config.js` and options
# Paste content of your `gatsby-config.js` file, and/or command line options here. Check there is no private info in there.
Environment
Environment
# Paste output from `npx envinfo` here.
Gatsby info
gatsby info
System:
OS: macOS 12.4
CPU: (16) x64 Intel(R) Core(TM) i7-10700K CPU @ 3.80GHz
Shell: 5.9 - /usr/local/bin/zsh
Binaries:
Node: 16.9.0 - ~/.nvm/versions/node/v16.9.0/bin/node
Yarn: 1.22.15 - ~/.nvm/versions/node/v16.9.0/bin/yarn
npm: 8.10.0 - ~/.nvm/versions/node/v16.9.0/bin/npm
Browsers:
Chrome: 101.0.4951.64
Firefox: 85.0
Safari: 15.5
npmPackages:
gatsby: ^4.11.2 => 4.14.1
gatsby-plugin-google-tagmanager: ^4.12.1 => 4.14.0
gatsby-plugin-image: ^2.11.1 => 2.14.1
gatsby-plugin-manifest: ^4.11.1 => 4.14.0
gatsby-plugin-netlify: ^4.3.1 => 4.4.0
gatsby-plugin-offline: ^5.11.1 => 5.14.1
gatsby-plugin-react-helmet: ^5.11.0 => 5.14.0
gatsby-plugin-sass: ^5.12.1 => 5.14.0
gatsby-plugin-sharp: ^4.11.1 => 4.14.1
gatsby-plugin-sitemap: ^5.12.1 => 5.14.0
gatsby-source-filesystem: ^4.11.1 => 4.14.0
gatsby-source-shopify: ^7.1.1 => 7.3.1
gatsby-source-storyblok: ^3.1.2 => 3.1.2
gatsby-transformer-sharp: ^4.11.0 => 4.14.0
npmGlobalPackages:
gatsby-cli: 4.14.0
Your _redirects file
`_redirects`
## Created with gatsby-plugin-netlify
/products /collections/all-products 301
/category/:collection /collections/:collection 301
/product/:product /products/:product 301
Builds logs (or link to your logs)
11:42:15 AM: Build ready to start
11:42:17 AM: build-image version: d2c6dbeac570350a387d832f64bc980dc964ad65 (focal)
11:42:17 AM: build-image tag: v4.8.0
11:42:17 AM: buildbot version: e694672a8289170fbd4455b79b331a0620566215
11:42:17 AM: Building without cache
11:42:17 AM: Starting to prepare the repo for build
11:42:17 AM: No cached dependencies found. Cloning fresh repo
11:42:17 AM: git clone https://github.com/edmeehan/gatsby-shopify-imrse-store
11:42:18 AM: Preparing Git Reference pull/14/head
11:42:18 AM: Parsing package.json dependencies
11:42:19 AM: Different functions path detected, going to use the one specified in the Netlify configuration file: 'my_functions' versus '' in the Netlify UI
11:42:19 AM: Starting build script
11:42:19 AM: Installing dependencies
11:42:19 AM: Python version set to 2.7
11:42:20 AM: Attempting node version 'v16.9.0' from .nvmrc
11:42:20 AM: Downloading and installing node v16.9.0...
11:42:20 AM: Downloading https://nodejs.org/dist/v16.9.0/node-v16.9.0-linux-x64.tar.xz...
11:42:21 AM: Computing checksum with sha256sum
11:42:21 AM: Checksums matched!
11:42:23 AM: Now using node v16.9.0 (npm v7.21.1)
11:42:23 AM: Started restoring cached build plugins
11:42:23 AM: Finished restoring cached build plugins
11:42:23 AM: Attempting ruby version 2.7.1, read from environment
11:42:24 AM: Required ruby-2.7.1 is not installed - installing.
11:42:24 AM: Searching for binary rubies, this might take some time.
11:42:24 AM: Found remote file https://rvm_io.global.ssl.fastly.net/binaries/ubuntu/20.04/x86_64/ruby-2.7.1.tar.bz2
11:42:24 AM: Checking requirements for ubuntu.
11:42:25 AM: Requirements installation successful.
11:42:25 AM: ruby-2.7.1 - #configure
11:42:25 AM: ruby-2.7.1 - #download
11:42:26 AM: ruby-2.7.1 - #validate archive
11:42:30 AM: ruby-2.7.1 - #extract
11:42:32 AM: ruby-2.7.1 - #validate binary
11:42:33 AM: ruby-2.7.1 - #setup
11:42:33 AM: ruby-2.7.1 - #gemset created /opt/buildhome/.rvm/gems/ruby-2.7.1@global
11:42:34 AM: ruby-2.7.1 - #importing gemset /opt/buildhome/.rvm/gemsets/global.gems........................................
11:42:34 AM: ruby-2.7.1 - #generating global wrappers........
11:42:34 AM: ruby-2.7.1 - #gemset created /opt/buildhome/.rvm/gems/ruby-2.7.1
11:42:34 AM: ruby-2.7.1 - #importing gemsetfile /opt/buildhome/.rvm/gemsets/default.gems evaluated to empty gem list
11:42:35 AM: ruby-2.7.1 - #generating default wrappers........
11:42:35 AM: Using /opt/buildhome/.rvm/gems/ruby-2.7.1
11:42:35 AM: Using ruby version 2.7.1
11:42:36 AM: Using PHP version 8.0
11:42:36 AM: No npm workspaces detected
11:42:36 AM: Started restoring cached node modules
11:42:36 AM: Finished restoring cached node modules
11:42:36 AM: Installing NPM modules using NPM version 7.21.1
11:42:48 AM: npm WARN deprecated source-map-url@0.4.1: See https://github.com/lydell/source-map-url#deprecated
11:42:48 AM: npm WARN deprecated urix@0.1.0: Please see https://github.com/lydell/urix#deprecated
11:42:48 AM: npm WARN deprecated resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated
11:42:48 AM: npm WARN deprecated source-map-resolve@0.5.3: See https://github.com/lydell/source-map-resolve#deprecated
11:42:49 AM: npm WARN deprecated uuid@3.4.0: Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details.
11:42:49 AM: npm WARN deprecated uuid@3.4.0: Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details.
11:42:50 AM: npm WARN deprecated storyblok-react@0.1.2: This package is deprecated. Please use @storyblok/react
11:42:50 AM: npm WARN deprecated querystring@0.2.1: The querystring API is considered Legacy. new code should use the URLSearchParams API instead.
11:42:54 AM: npm WARN deprecated subscriptions-transport-ws@0.9.19: The subscriptions-transport-ws
package is no longer maintained. We recommend you use graphql-ws
instead. For help migrating Apollo software to graphql-ws
, see https://www.apollographql.com/docs/apollo-server/data/subscriptions/#switching-from-subscriptions-transport-ws For general help using graphql-ws
, see https://github.com/enisdenjo/graphql-ws/blob/master/README.md
11:42:56 AM: npm WARN deprecated async-cache@1.1.0: No longer maintained. Use lru-cache version 7.6 or higher, and provide an asynchronous fetchMethod
option.
11:42:56 AM: npm WARN deprecated babel-eslint@10.1.0: babel-eslint is now @babel/eslint-parser. This package will no longer receive updates.
11:42:57 AM: npm WARN deprecated @storyblok/storyblok-editable@1.1.0: This package is deprecated. Please use the Storyblok SDK for React or Gatsby. Or you can use the @storyblok/js package
11:42:58 AM: npm WARN deprecated @hapi/bourne@1.3.2: This version has been deprecated and is no longer supported or maintained
11:42:58 AM: npm WARN deprecated svgo@1.3.2: This SVGO version is no longer supported. Upgrade to v2.x.x.
11:42:58 AM: npm WARN deprecated @hapi/address@2.1.4: Moved to 'npm install @sideway/address'
11:43:02 AM: npm WARN deprecated @hapi/topo@3.1.6: This version has been deprecated and is no longer supported or maintained
11:43:02 AM: npm WARN deprecated @hapi/joi@15.1.1: Switch to 'npm install joi'
11:43:02 AM: npm WARN deprecated @hapi/hoek@8.5.1: This version has been deprecated and is no longer supported or maintained
11:43:03 AM: npm WARN deprecated devcert@1.2.0: critical regex denial of service bug fixed in 1.2.1 patch
11:43:11 AM: npm WARN deprecated core-js@2.6.12: core-js@<3.4 is no longer maintained and not recommended for usage due to the number of issues. Because of the V8 engine whims, feature detection in old core-js versions could cause a slowdown up to 100x even if nothing is polyfilled. Please, upgrade your dependencies to the actual version of core-js.
11:43:24 AM: added 1848 packages, and audited 1849 packages in 47s
11:43:24 AM: 243 packages are looking for funding
11:43:24 AM: run npm fund
for details
11:43:24 AM: 30 vulnerabilities (6 moderate, 24 high)
11:43:24 AM: To address issues that do not require attention, run:
11:43:24 AM: npm audit fix
11:43:24 AM: To address all issues (including breaking changes), run:
11:43:24 AM: npm audit fix --force
11:43:24 AM: Run npm audit
for details.
11:43:24 AM: NPM modules installed
11:43:24 AM: Started restoring cached go cache
11:43:24 AM: Finished restoring cached go cache
11:43:24 AM: Installing Go version 1.14.4
11:43:30 AM: unset GOOS;
11:43:30 AM: unset GOARCH;
11:43:30 AM: export GOROOT='/opt/buildhome/.gimme_cache/versions/go1.14.4.linux.amd64';
11:43:30 AM: export PATH="/opt/buildhome/.gimme_cache/versions/go1.14.4.linux.amd64/bin:${PATH}";
11:43:30 AM: go version >&2;
11:43:30 AM: export GIMME_ENV="/opt/buildhome/.gimme_cache/env/go1.14.4.linux.amd64.env"
11:43:30 AM: go version go1.14.4 linux/amd64
11:43:30 AM: Installing missing commands
11:43:30 AM: Verify run directory
11:43:31 AM:
11:43:31 AM: ────────────────────────────────────────────────────────────────
11:43:31 AM: Netlify Build
11:43:31 AM: ────────────────────────────────────────────────────────────────
11:43:31 AM:
11:43:31 AM: ❯ Version
11:43:31 AM: @netlify/build 27.1.2
11:43:31 AM:
11:43:31 AM: ❯ Flags
11:43:31 AM: baseRelDir: true
11:43:31 AM: buildId: 62868f876057542235de1c97
11:43:31 AM: deployId: 62868f876057542235de1c99
11:43:31 AM:
11:43:31 AM: ❯ Current directory
11:43:31 AM: /opt/build/repo
11:43:31 AM:
11:43:31 AM: ❯ Config file
11:43:31 AM: /opt/build/repo/netlify.toml
11:43:31 AM:
11:43:31 AM: ❯ Context
11:43:31 AM: deploy-preview
11:43:31 AM:
11:43:31 AM: ❯ Installing plugins
11:43:31 AM: - @netlify/plugin-gatsby@3.0.0
11:43:42 AM:
11:43:42 AM: ❯ Loading plugins
11:43:42 AM: - @netlify/plugin-gatsby@3.0.0 from Netlify app
11:43:43 AM:
11:43:43 AM: ────────────────────────────────────────────────────────────────
11:43:43 AM: 1. @netlify/plugin-gatsby (onPreBuild event)
11:43:43 AM: ────────────────────────────────────────────────────────────────
11:43:43 AM:
11:43:43 AM: No Gatsby cache found. Building fresh.
11:43:43 AM:
11:43:43 AM: (@netlify/plugin-gatsby onPreBuild completed in 15ms)
11:43:43 AM:
11:43:43 AM: ────────────────────────────────────────────────────────────────
11:43:43 AM: 2. Build command from Netlify app
11:43:43 AM: ────────────────────────────────────────────────────────────────
11:43:43 AM:
11:43:43 AM: $ gatsby build
11:43:46 AM: success compile gatsby files - 0.698s
11:43:46 AM: success load gatsby config - 0.047s
11:43:46 AM: warning Warning: there are unknown plugin options for "gatsby-plugin-sass": additionalData
11:43:46 AM: Please open an issue at https://ghub.io/gatsby-plugin-sass if you believe this option is valid.
11:43:46 AM: success load plugins - 0.515s
11:43:46 AM: success onPreInit - 0.004s
11:43:46 AM: success initialize cache - 0.052s
11:43:46 AM: success copy gatsby files - 0.141s
11:43:47 AM: success Compiling Gatsby Functions - 0.200s
11:43:47 AM: success onPreBootstrap - 0.209s
11:43:47 AM: success createSchemaCustomization - 0.020s
11:43:48 AM: info Running non-priority queries
11:43:51 AM: warning Warning: there are unknown plugin options for "gatsby-plugin-sass": additionalData
11:43:51 AM: Please open an issue at https://ghub.io/gatsby-plugin-sass if you believe this option is valid.
11:43:52 AM: warning Warning: there are unknown plugin options for "gatsby-plugin-sass": additionalData
11:43:52 AM: Please open an issue at https://ghub.io/gatsby-plugin-sass if you believe this option is valid.
11:43:52 AM: warning Warning: there are unknown plugin options for "gatsby-plugin-sass": additionalData
11:43:52 AM: Please open an issue at https://ghub.io/gatsby-plugin-sass if you believe this option is valid.
11:43:53 AM: success source shopify products - 5.587s - 23 nodes
11:44:03 AM: success source shopify variants - 9.279s - 231 nodes
11:44:05 AM: success source shopify collections - 2.403s - 7 nodes
11:44:05 AM: success Checking for changed pages - 0.000s
11:44:05 AM: success source and transform nodes - 18.273s
11:44:05 AM: info Writing GraphQL type definitions to /opt/build/repo/.cache/schema.gql
11:44:06 AM: success building schema - 0.542s
11:44:06 AM: success createPages - 0.148s
11:44:06 AM: success createPagesStatefully - 0.065s
11:44:06 AM: info Total nodes: 454, SitePage nodes: 40 (use --verbose for breakdown)
11:44:06 AM: success Checking for changed pages - 0.000s
11:44:06 AM: success onPreExtractQueries - 0.000s
11:44:09 AM: success extract queries from components - 3.281s
11:44:09 AM: warning The GraphQL query in the non-page component "/opt/build/repo/src/templates/PostListing.jsx" will not be run.
11:44:09 AM: Exported queries are only executed for Page components. It's possible you're
11:44:09 AM: trying to create pages in your gatsby-node.js and that's failing for some
reason.
11:44:09 AM: If the failing component(s) is a regular component and not intended to be a page
11:44:09 AM: component, you generally want to use a (https://gatsbyjs.com/docs/static-query)
11:44:09 AM: instead of exporting a page query.
11:44:09 AM: If you're more experienced with GraphQL, you can also export GraphQL
fragments from components and compose the fragments in the Page component
11:44:09 AM: query and pass data down into the child component — https://graphql.org/learn/queries/#fragments
11:44:09 AM: success write out redirect data - 0.005s
11:44:09 AM: success Build manifest and related icons - 0.219s
11:44:09 AM: success onPostBootstrap - 0.221s
11:44:09 AM: info bootstrap finished - 26.352s
11:44:09 AM: success write out requires - 0.005s
11:44:35 AM: success Building production JavaScript and CSS bundles - 25.555s
11:44:52 AM: success Building HTML renderer - 17.662s
11:44:53 AM: success Execute page configs - 0.020s
11:44:53 AM: success Caching Webpack compilations - 0.000s
11:44:53 AM: success run queries in workers - 0.209s - 44/44 210.45/s
11:44:53 AM: success Merge worker state - 0.002s
11:44:53 AM: success Rewriting compilation hashes - 0.000s
11:44:53 AM: success Writing page-data.json files to public directory - 0.008s - 40/40 4774.14/s
11:44:58 AM: success Building static HTML for pages - 4.539s - 40/40 8.81/s
11:44:58 AM: info [gatsby-plugin-netlify] Creating SSR/DSG redirects...
11:44:58 AM: info [gatsby-plugin-netlify] Created 0 SSR/DSG redirects...
11:44:58 AM: success onPostBuild - 0.048s
11:44:58 AM:
11:44:58 AM: Pages
11:44:58 AM: ┌ src/templates/Collection.jsx
11:44:58 AM: │ ├ /collections/apparel
11:44:58 AM: │ └ ...6 more pages available
11:44:58 AM: ├ src/templates/Product.jsx
11:44:58 AM: │ ├ /products/long-sleeve-flow-rash-guard
11:44:58 AM: │ └ ...22 more pages available
11:44:58 AM: ├ src/templates/Page.jsx
11:44:58 AM: │ ├ /thank-you
11:44:58 AM: │ └ ...8 more pages available
11:44:58 AM: └ src/templates/Global.jsx
11:44:58 AM: └ /global
11:44:58 AM: ╭────────────────────────────────────────────────────────────────────╮
11:44:58 AM: │ │
11:44:58 AM: │ (SSG) Generated at build time │
11:44:58 AM: │ D (DSG) Deferred static generation - page generated at runtime │
11:44:58 AM: │ ∞ (SSR) Server-side renders at runtime (uses getServerData) │
11:44:58 AM: │ λ (Function) Gatsby function │
11:44:58 AM: │ │
11:44:58 AM: ╰────────────────────────────────────────────────────────────────────╯
11:44:58 AM: info Done building in 75.569813798 sec
11:44:59 AM:
11:45:00 AM: Creating deploy upload records
11:44:59 AM: (build.command completed in 1m 15.7s)
11:44:59 AM:
11:44:59 AM: ────────────────────────────────────────────────────────────────
11:44:59 AM: 3. @netlify/plugin-gatsby (onBuild event)
11:44:59 AM: ────────────────────────────────────────────────────────────────
11:44:59 AM:
11:44:59 AM: Skipping Gatsby Functions and SSR/DSG support because gatsby-plugin-netlify reported that this site does not use them.
11:44:59 AM: If this is incorrect, remove the file "/opt/build/repo/.cache/.nf-skip-gatsby-functions" and try again.
11:44:59 AM:
11:44:59 AM: (@netlify/plugin-gatsby onBuild completed in 6ms)
11:44:59 AM:
11:44:59 AM: ────────────────────────────────────────────────────────────────
11:44:59 AM: 4. Functions bundling
11:45:00 AM: Starting post processing
11:44:59 AM: ────────────────────────────────────────────────────────────────
11:44:59 AM:
11:44:59 AM: The Netlify Functions setting targets a non-existing directory: my_functions
11:44:59 AM:
11:45:00 AM: Post processing - HTML
11:44:59 AM: (Functions bundling completed in 2ms)
11:44:59 AM:
11:44:59 AM: ────────────────────────────────────────────────────────────────
11:44:59 AM: 5. @netlify/plugin-gatsby (onPostBuild event)
11:45:00 AM: Processing form - contact
11:44:59 AM: ────────────────────────────────────────────────────────────────
11:44:59 AM:
11:44:59 AM: Could not check zip size because /tmp/zisi-62868f876057542235de1c99/__api.zip does not exist
11:44:59 AM: Could not check zip size because /tmp/zisi-62868f876057542235de1c99/__dsg.zip does not exist
11:45:01 AM: Detected form fields:
- name
- bot-field
- subject
- message
11:44:59 AM: Could not check zip size because /tmp/zisi-62868f876057542235de1c99/__ssr.zip does not exist
11:44:59 AM:
11:44:59 AM: (@netlify/plugin-gatsby onPostBuild completed in 820ms)
11:44:59 AM:
11:44:59 AM: ────────────────────────────────────────────────────────────────
11:44:59 AM: 6. Deploy site
11:44:59 AM: ────────────────────────────────────────────────────────────────
11:44:59 AM:
11:44:59 AM: Starting to deploy site from 'public'
11:45:01 AM: Post processing - header rules
11:44:59 AM: Creating deploy tree
11:45:00 AM: 0 new files to upload
11:45:00 AM: 0 new functions to upload
11:45:00 AM: Site deploy was successfully initiated
11:45:00 AM:
11:45:00 AM: (Deploy site completed in 303ms)
11:45:00 AM:
11:45:01 AM: Post processing - redirect rules
11:45:00 AM: ────────────────────────────────────────────────────────────────
11:45:00 AM: Netlify Build Complete
11:45:00 AM: ────────────────────────────────────────────────────────────────
11:45:00 AM:
11:45:00 AM: (Netlify Build completed in 1m 29s)
11:45:00 AM: Caching artifacts
11:45:00 AM: Started saving node modules
11:45:00 AM: Finished saving node modules
11:45:00 AM: Started saving build plugins
11:45:01 AM: Post processing done
11:45:00 AM: Finished saving build plugins
11:45:00 AM: Started saving pip cache
11:45:00 AM: Finished saving pip cache
11:45:00 AM: Started saving emacs cask dependencies
11:45:00 AM: Finished saving emacs cask dependencies
11:45:00 AM: Started saving maven dependencies
11:45:00 AM: Finished saving maven dependencies
11:45:00 AM: Started saving boot dependencies
11:45:00 AM: Finished saving boot dependencies
11:45:00 AM: Started saving rust rustup cache
11:45:00 AM: Finished saving rust rustup cache
11:45:00 AM: Started saving go dependencies
11:45:01 AM: Finished saving go dependencies
11:45:03 AM: Cached ruby version 2.7.1
11:45:03 AM: Build script success
11:45:05 AM: Site is live ✨
11:46:09 AM: Finished processing build request in 3m52.753476292s
Function logs
No response
I reviewed the build files from Netlify and it does not appear to be making a _redirects file on Netlify build, but is working with my local build. I don't see any errors related to this in the log, so not sure if this is a plugin issue or netlify issue.
It does seem odd that the _redirects file is getting created on local build but not when you run netlify build
. I'm unable to reproduce the issue following the steps you provided. Are you able to provide a reproduction repo so I can investigate further?
I have found the issue, but don't know a solution. It appears that it is my async/await used on the graphQL to crate pages, and also to create redirects (since my redirect rules are stored on StoryBlok CMS).
This seems to be a race condition with the plugin and the graphQL response and the calls to createRedirect
exports.createPages = async ({ graphql, actions }) => {
const { createPage, createRedirect } = actions;
// below works as expected and written to _redirects file on netlify build
createRedirect({
fromPath: '/test',
toPath: '/always',
statusCode: 301,
});
const { data } = await graphql(`just empty but big query would be here`);
// works locally with gatsby build - does not work on netlify build
data.forEach(({to:toPath,from:fromPath,status:statusCode}) => createRedirect({
fromPath,
toPath,
statusCode,
}))
}
I attempted to recreate this race condition with the following code, but unfortunately I'm still unable to reproduce the error. The _redirects file is created as expected and the redirects work after deployment.
exports.createPages = async ({ graphql, actions }) => {
const { createRedirect } = actions;
createRedirect({
fromPath: `/testbefore`,
toPath: `/`,
});
function Wait() {
return new Promise((resolve) => {
setTimeout(resolve, 10000, 100);
});
}
const test = await Wait();
createRedirect({
fromPath: `/testafter`,
toPath: `/`,
});
};
If you can provide a minimal reproduction that exhibits the bug I'd be happy to investigate further.