Giter Site home page Giter Site logo

netlify / netlify-plugin-gatsby Goto Github PK

View Code? Open in Web Editor NEW
89.0 8.0 18.0 46.26 MB

A build plugin to integrate Gatsby seamlessly with Netlify

Home Page: https://www.npmjs.com/package/@netlify/plugin-gatsby

License: MIT License

JavaScript 19.71% Shell 0.47% TypeScript 79.23% CSS 0.58%
netlify netlify-plugin gatsby gatsbyjs javascript

netlify-plugin-gatsby's Introduction

Netlify Build plugin Gatsby – Run Gatsby seamlessly on Netlify

Essential Gatsby Plugin

The Essential Gatsby build plugin enables caching of builds, SSR and DSG render modes, image CDN and Gatsby Functions. It is installed automatically for all new Gatsby sites.

Note:

Installation

Gatsby sites need two plugins to support all features.

  1. The Netlify build plugin, called "Essential Gatsby" or @netlify/plugin-gatsby. This is installed automatically for all Gatsby sites deployed to Netlify.
  2. The Gatsby plugin gatsby-plugin-netlify. This needs to be manually installed.

Installing the Netlify build plugin

New Gatsby sites on Netlify automatically install the Essential Gatsby build plugin. You can confirm this in the build logs. If you need to install it manually, you have two options:

Install the Gatsby Plugin

You should also install the Gatsby plugin gatsby-plugin-netlify. This is required for SSR and DSG pages, and adds support for Gatsby redirects and asset caching rules:

  1. Add the package as a dependency:
npm install -D gatsby-plugin-netlify
  1. Then add the following to your gatsby-config.js file:
module.exports = {
  plugins: ['gatsby-plugin-netlify'],
}

See the gatsby-plugin-netlify docs for more information, including optional plugin configuration.

Disabling Netlify functions

In order to support Gatsby Functions and DSG and SSR render modes, this plugin generates four Netlify Functions called __api, __ssr, __dsg and _ipx. If you are not using any of these modes, then you can disable the creation of these functions. If you are using the latest version of gatsby-plugin-netlify then this will be handled automatically, disabling functions if the site has no Gatsby Functions, or DSG/SSR pages. Otherwise, you can do this manually by setting the environment variable NETLIFY_SKIP_GATSBY_FUNCTIONS to true. Be aware that if you do this, any DSG or SSR pages will not work, and nor will any Gatsby Functions or the remote image CDN.

Gatsby Image CDN

Gatsby includes beta support for deferred image resizing using a CDN. Netlify includes full support for Image CDN on all plans. For details on how to enable it, see the image CDN docs.

Caveats

Currently you cannot use StaticImage or gatsby-transformer-sharp in SSR or DSG pages. Support for Gatsby Image CDN is coming soon. The best workaround is to use an image CDN such as Cloudinary or imgix to host your images. This will give you faster builds and rendering too.

Local development

When developing Gatsby Functions it is usually easier to use the built-in gatsby develop functions server. However if you want to try the Netlify functions wrapper it will run via netlify dev. You should be sure to run netlify build first, so that the wrappers are generated and the functions copied across.

Netlify Background and Scheduled Functions

In order to use Netlify Background or Netlify Scheduled Functions in your Gatsby project, you will need to create a netlify/functions directory at the root of the project, and put the Functions in there.

Once that's completed, the Background or Scheduled Function can be invoked like an ordinary Gatsby function.

netlify-plugin-gatsby's People

Contributors

ascorbic avatar biruwon avatar dustincrogers avatar ehmicky avatar erezrokah avatar ericapisani avatar ikristy avatar kathmbeck avatar lukeocodes avatar marcl avatar nickytonline avatar orinokai avatar pcn avatar pieh avatar renovate-bot avatar renovate[bot] avatar rstavchansky avatar sarahetter avatar stephenjbradshaw avatar taty2010 avatar token-generator-app[bot] avatar xhmikosr avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

netlify-plugin-gatsby's Issues

Improve error handling

At the moment, the code is wrapped in top-level try/catch blocks.

utils.build.failBuild('Error message', { error })

This pattern would create the following problems:

  • This does not distinguish between plugin errors and user errors. Namely: every exception will be reported as a user error.
  • Prefixing error messages with Error message might be redundant
  • Since Bugsnag groups errors using the error message, all errors will be grouped together in Bugsnag, which will not allow us to see new error instances and might take away some of the benefits of error monitoring

Instead, most plugins usually follow the following pattern:

  • Wrap try/catch block around each specific function or line of code that might throw due to user errors
  • For each of those, use a descriptive error message for the specific case
  • Avoid wrapping the whole code with try/catch so that plugin bugs exceptions are propagated and reported as plugin errors

It seems like the only place where a user error might throw at the moment is when loading gatsby-config.js, i.e. this might be the only place which would need a try/catch block.

Does not deploy Lambda function when Netlify redirects are defined

Describe the bug

First I'm not 100% sure if this is a bug with Netlify (the Netlify CLI itself) or if it's related to this plugin. So hopefully someone with more insights can help here: when there is already a _redirects file defined in the static/ directory this plugin indeed does create correctly the following entry at the end of the file

## Created with gatsby-plugin-netlify
/foo/*  /  301
# @netlify/plugin-gatsby redirects start
/api/* /.netlify/functions/gatsby 200
# @netlify/plugin-gatsby redirects end

but the Lambda function itself is not deployed. From the Netlify CLI I'm getting

(Netlify Build completed in 3m 26.6s)
Deploy path:        /Users/me/Workspace/some-site/public
Configuration path: /Users/me/Workspace/some-site/netlify.toml
Deploying to draft URL...
✔ Finished hashing 4242 files
✔ CDN requesting 42 files
✔ Finished uploading 42 assets
✔ Deploy is live!

When I completely remove the static/_redirects file the Netlify CLI output is

(Netlify Build completed in 3m 31.2s)
Deploy path:        /Users/me/Workspace/some-site/public
Functions path:     /Users/me/Workspace/some-site/netlify/functions
Configuration path: /Users/me/Workspace/some-site/netlify.toml
Deploying to draft URL...
✔ Deploying functions from cache (use --skip-functions-cache to override)
✔ Finished hashing 4242 files and 1 functions
✔ CDN requesting 42 files and 0 functions
✔ Finished uploading 42 assets
✔ Deploy is live!

On the third line there is the indicator that the function is found and deployed. I'm using additionally gatsby-plugin-netlify in combination with @netlify/plugin-gatsby.

Steps to reproduce

  1. create a new Gatsby project
  2. create a Lambda function in src/api/
  3. create a static/_redirects file with one or more redirects. For example /foo/* / 301
  4. build the project with npx netlify deploy --build

The same happens when a _redirects file is not present but created programatically in gatsby-node.js with

exports.createPages = async ({ actions }) => {
  const { createRedirect } = actions;

  createRedirect({
    fromPath: '/foo/*',
    toPath: '/',
    statusCode: 301,
  });
};

Expected behavior

A Netlify Lambda function should be deployed

Configuration

Environment

$ npx envinfo --system --binaries --browsers --npmPackages @netlify/plugin-gatsby

  System:
    OS: macOS 12.1
    CPU: (8) arm64 Apple M1
    Memory: 2.16 GB / 16.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 16.13.2 - /var/folders/85/8rb_y49j5911bg5qzd7tkddw0000gp/T/fnm_multishells/78765_1642439901724/bin/node
    npm: 8.1.2 - /var/folders/85/8rb_y49j5911bg5qzd7tkddw0000gp/T/fnm_multishells/78765_1642439901724/bin/npm
  Browsers:
    Chrome: 97.0.4692.71
    Edge: 97.0.1072.62
    Firefox Developer Edition: 92.0
    Safari: 15.2
  npmPackages:
    @netlify/plugin-gatsby: 1.0.3 => 1.0.3

plus I'm using "gatsby-plugin-netlify": "3.14.0" and Gatsby v3 (3.14.5)

Screenshots

Can you submit a pull request?

No.

Netlify DSG page failed with 500 server error when using custom source plugin.

Describe the bug

Hi, we are upgrading to gatsbyv4 and using netlify to host our site. While adding DSG support for several pages. Unexpected behavior was seen.
When the site is deployed for the very first time.
DSG pages give 500 internal errors on DSG enabled pages.

When I redeploy without clearing cache these pages automatically work.
These are the logs for the _dsg function.

Feb 13, 10:21:00 PM: ebd60328 error Error: ENOENT: no such file or directory, open '/opt/build/repo/.cache/caches/gatsby-source-custom-api/44b5d8b9f62a9d1bf85708e10185900a/EoHoW6.jpeg' Feb 13, 10:21:00 PM: ebd60328 at Object.openSync (fs.js:497:3) Feb 13, 10:21:00 PM: ebd60328 at Object.readFileSync (fs.js:393:35)Feb 13, 10:21:00 PM: ebd60328 at Object.lfs.<computed> [as readFileSync] (/var/task/.netlify/functions-internal/__dsg/__dsg.js:3284:24)Feb 13, 10:21:00 PM: ebd60328 at Function.hasha.fromFileSync (/var/task/.cache/query-engine/index.js:175592:54) Feb 13, 10:21:00 PM: ebd60328 at createFileHash (/var/task/.cache/query-engine/index.js:175130:25) Feb 13, 10:21:00 PM: ebd60328 at /var/task/.cache/query-engine/index.js:175283:22 Feb 13, 10:21:00 PM: ebd60328 at Array.map (<anonymous>) Feb 13, 10:21:00 PM: ebd60328 at createInternalJob (/var/task/.cache/query-engine/index.js:175280:50) Feb 13, 10:21:00 PM: ebd60328 at /var/task/.cache/query-engine/index.js:177000:23Feb 13, 10:21:00 PM: ebd60328 at /var/task/.cache/query-engine/index.js:52897:18Feb 13, 10:21:00 PM: ebd60328 at /var/task/.cache/query-engine/index.js:26666:12Feb 13, 10:21:00 PM: ebd60328 at Object.doubleBoundActionCreators.<computed> [as createJobV2] (/var/task/.cache/query-engine/index.js:160607:20) Feb 13, 10:21:00 PM: ebd60328 at createJob (/var/task/.cache/query-engine/index.js:186952:27)Feb 13, 10:21:00 PM: ebd60328 at batchQueueImageResizing (/var/task/.cache/query-engine/index.js:187044:27) Feb 13, 10:21:00 PM: ebd60328 at generateImageData (/var/task/.cache/query-engine/index.js:193095:48) Feb 13, 10:21:00 PM: ebd60328 at resolve (/var/task/.cache/query-engine/index.js:292538:25) Feb 13, 10:21:00 PM: ebd60328 Duration: 100.57 ms Memory Usage: 578 MB

It's very unclear to me why this is happening. gatsby-plugin-image is supposed to cache all the images automatically.
Or
the reason is because netlify-plugin-gatsby still doesn't support images as mentioned that staticImage and some others are still not supported?

Sidenote:
We are using aws s3 for hosting images.

Expected Behavior:
If the DSG pages are being rendered properly on second deploy then they are supposed to be working on first ever deployment also.

Screenshots

image

Link to URL with DSG enabled:
https://62012bfbdcbc1d0008521095--tender-galileo-fdd375.netlify.app/products/1200-peak-amp-portable-car-jump-starterportable-power-station-with-120-psi-compressor-and-500-watt-p/
This URL might be working right now for you because I've already redeployed the site.

Plugin generating incorrect API urls

I'm trying to deploy my site to Netlify, but my Gatsby Function API routes are not working. When I go to them directly, I'm served the following error. The only place I have node-fetch is as a dependency of this plugin

https://imgur.com/QK1jUKy

Do I need something special in my toml file besides the plugin import? Appreciate any help/guidance 🙏

Add a `engines.node` field in `package.json`

When an engines.node field is present in package.json, our builds will show some nice error message when a site is using a Node.js version that's too old for this plugin. This provides with a better user experience (otherwise the plugin might crash in a more obscure way).

Would it make sense to add this field in package.json, based on the minimum Node.js version?

Error: Cannot find module 'lmdb-store'

I'm getting this error with the Gatsby 4.8.0

Gatsby 4.8.0 has upgrade from lmdb-store to lmdb

Error: Cannot find module 'lmdb-store'
Require stack:
- /opt/build/repo/.netlify/plugins/node_modules/@netlify/plugin-gatsby/lib/helpers/files.js
- /opt/build/repo/.netlify/plugins/node_modules/@netlify/plugin-gatsby/lib/index.js

Action Required: Fix Renovate Configuration

There is an error with this repository's Renovate configuration that needs to be fixed. As a precaution, Renovate will stop PRs until it is resolved.

Error type: Cannot find preset's package (github>whitesource/merge-confidence:beta)

Redirect not working

I have a gatsby website that uses following dependencies:

"gatsby-plugin-netlify": "^4.0.0-next.0",
"@netlify/plugin-gatsby": "^2.0.0-beta",
"netlify-lambda": "^2.0.5",
"gatsby": "^4.4.0",

I added gatsby-plugin-netlify into gatsby-config.js file as well.
I installed Essential Gatsby plugin on Netlify and setup the _redirect file in static directory like this:

/api/* /.netlify/functions/:splat 200

Here's the build log:
https://app.netlify.com/sites/owyn-dev/deploys/61d5e257ba53870008adcd28#L405

This is the request curl command that I use for testing:

curl --location --request POST 'https://deploy-preview-444--owyn-dev.netlify.app/api/cart/' \
--header 'Content-Type: application/json' \
--header 'Cookie: cartId=73a03db428934ea9b73cbce5460a6396' \
--data-raw '[
    {
        "quantity": 1,
        "variantId": "41001415540924"
    }
]'

But this redirect configuration doesn't work on staging website. I need help on this asap.

Thank you

Failing build: Failed to upload file: __ssr Failed to upload file: __dsg

Describe the bug

Build fails for gatsby v4.1.0 and @netlify/[email protected] while works with stable version of @netlify/plugin-gatsby (of course without dsg and ssr)

Here the logs:

10:54:59 AM: ────────────────────────────────────────────────────────────────
10:54:59 AM:   6. Deploy site                                                
10:54:59 AM: ────────────────────────────────────────────────────────────────
10:54:59 AM: ​
10:54:59 AM: Starting to deploy site from 'public'
10:55:14 AM: Creating deploy tree asynchronously
10:55:14 AM: Creating deploy upload records
10:55:20 AM: 79 new files to upload
10:55:20 AM: 3 new functions to upload
10:55:26 AM: Request must be smaller than 69905067 bytes for the CreateFunction operation
10:55:26 AM: Request must be smaller than 69905067 bytes for the CreateFunction operation
10:55:28 AM: Request must be smaller than 69905067 bytes for the CreateFunction operation
10:55:28 AM: Request must be smaller than 69905067 bytes for the CreateFunction operation
10:55:30 AM: Request must be smaller than 69905067 bytes for the CreateFunction operation
10:55:30 AM: Request must be smaller than 69905067 bytes for the CreateFunction operation
10:55:31 AM: Request must be smaller than 69905067 bytes for the CreateFunction operation
10:55:32 AM: Request must be smaller than 69905067 bytes for the CreateFunction operation
10:55:34 AM: Request must be smaller than 69905067 bytes for the CreateFunction operation
10:55:35 AM: Request must be smaller than 69905067 bytes for the CreateFunction operation
10:55:38 AM: Request must be smaller than 69905067 bytes for the CreateFunction operation
10:55:38 AM: Request must be smaller than 69905067 bytes for the CreateFunction operation
10:55:42 AM: Request must be smaller than 69905067 bytes for the CreateFunction operation
10:55:42 AM: Request must be smaller than 69905067 bytes for the CreateFunction operation
10:55:50 AM: Request must be smaller than 69905067 bytes for the CreateFunction operation
10:55:51 AM: Request must be smaller than 69905067 bytes for the CreateFunction operation
10:55:58 AM: Request must be smaller than 69905067 bytes for the CreateFunction operation
10:55:59 AM: Request must be smaller than 69905067 bytes for the CreateFunction operation
10:56:12 AM: Request must be smaller than 69905067 bytes for the CreateFunction operation
10:56:18 AM: Request must be smaller than 69905067 bytes for the CreateFunction operation
10:56:23 AM: Request must be smaller than 69905067 bytes for the CreateFunction operation
10:56:34 AM: Request must be smaller than 69905067 bytes for the CreateFunction operation
10:56:51 AM: Request must be smaller than 69905067 bytes for the CreateFunction operation
10:56:51 AM: Failed to upload file: __ssr
10:56:52 AM: Failed to upload file: __dsg
10:56:52 AM: Site deploy was successfully initiated
10:56:52 AM: Execution cancelled
10:56:52 AM: Error running command: Command was cancelled
10:56:52 AM: Failing build: Failed to build site

Environment
Netlify CI:
node v14.18.1 (npm v6.14.15)
@netlify/build 18.21.3
npmPackages:
@netlify/plugin-gatsby: ^2.0.0-beta => 2.0.0-zz-beta.0
gatsby: ^4.1.0 => 4.1.0

Instead of showing the 404 page, non-existing pages are pointing to Netlify functions

When using the default gatsby-plugin-netlify and @netlify/plugin-gatsby using the instructions on the README, all Not Found Urls are being redirected to this weird page that seems to be trying to load a Netlify Function. The page returns a 502 status and shows

{"errorType":"Error","errorMessage":"ENOENT: no such file or directory, lstat '/var/task/.cache/data'","trace":["Error: ENOENT: no such file or directory, lstat '/var/task/.cache/data'","    at Object.lstatSync (fs.js:1119:3)","    at Object.lstatSync (/var/task/.netlify/functions-internal/__dsg/__dsg.js:466:38)","    at statFunc (/var/task/.netlify/functions-internal/__dsg/__dsg.js:1172:106)","    at getStatsSync (/var/task/.netlify/functions-internal/__dsg/__dsg.js:1173:23)","    at Object.checkPathsSync (/var/task/.netlify/functions-internal/__dsg/__dsg.js:1211:37)","    at copySync2 (/var/task/.netlify/functions-internal/__dsg/__dsg.js:1311:42)","    at prepareFilesystem (/var/task/.netlify/functions-internal/__dsg/__dsg.js:2929:32)","    at getHandler (/var/task/.netlify/functions-internal/__dsg/__dsg.js:2954:3)","    at Object.<anonymous> (/var/task/.netlify/functions-internal/__dsg/__dsg.js:3002:45)","    at Module._compile (internal/modules/cjs/loader.js:1085:14)"]}

I am using the latest Gatsby v4 and the latest Netlify plugins, and only do calls to createPage in gatsby-node to create content pages. I have no SSR or DSG pages. Everything is generated into a static file.

During the Netlify build, this message caught my attention:

1:31:13 AM: ────────────────────────────────────────────────────────────────
1:31:13 AM:   3. @netlify/plugin-gatsby (onBuild event)                     
1:31:13 AM: ────────────────────────────────────────────────────────────────
1:31:13 AM: ​
1:31:13 AM: Netlify configuration property "redirects" value changed to [ { from: '/*', to: '/.netlify/functions/__dsg', status: 200 } ].

Gatsby DSG Build on Netlify fails due to function size

My gatsby build on netlify fails due to the size of the DSG/SSR functions which are created by netlify-plugin-gatsby. Error produced is Request must be smaller than 69905067 bytes for the CreateFunction operation.

Additionally, during the 'onPostbuild' section of the build, I get the following message:
The function zip ../../../tmp/zisi-6212bb95da69157a8c04d77d/__ssr.zip size is 266 MB, which is larger than the maximum supported size of 52.4 MB.

I'm able to get my build to function locally but when I serve the site, the DSG pages (which get successfully built as specified in build output log) don't work and return 404's.

Build is running @netlify/plugin-gatsby 2.0.2 & gatsby 4.5.3.

I've contacted Netlify support, and they suggested this is to do with the functions from this plugin and not Netlify itself - they're hitting AWS's size limitation.

Any help would be greatly appreciated!

Could not find a binding for Linux 64-bit with Node.js 12.x

Describe the bug

I'm receiving the following error in my builds after installing gatsby-plugin-netlify instead of the old gatsby cache plugin. I've tried Clear cache and deploy site and rebuilding my lock file.

Previouly, node 15 has worked well but something is happening with my node-sass package combined with this plugin. I also have my gastby-config in a ts file that has been transpiling to JS during the build, which might also be connected here.

Is there anything I could do to inspect this error? I'm not sure how to debug this since it's in the onPreBuild phase.

Plugin "@netlify/plugin-gatsby" failed

Error: Could not load gatsby-config.js
Missing binding /opt/build/repo/node_modules/node-sass/vendor/linux-x64-72/binding.node
Node Sass could not find a binding for your current environment: Linux 64-bit with Node.js 12.x

Found bindings for the following environments:

Linux 64-bit with Node.js 15.x

This usually happens because your environment has changed since running npm install.
Run npm rebuild node-sass to download the binding for your current environment.

(Previously reported in netlify/gatsby-plugin-netlify#28.)

Steps to reproduce

My project is open-source, so you can see a failed build with the following:

Expected behavior

Builds are successful. 🤣

Configuration

It was installed via the UI. My netlify build script is set to npm run build:production, which maps to gatsby build

Environment

I'm not sure how to run the npx command since this is on the onPreBuild phase. If there's a good way, please let me know. I have my full build log here, I hope that it helps!

Full log from a failed build
6:36:50 PM: Build ready to start
6:36:53 PM: build-image version: dd2f6d8803393d46ac35a4f752a5a46f254c0300
6:36:53 PM: build-image tag: v3.9.1
6:36:53 PM: buildbot version: 349bc0ff8daba7d6ea8d12b21f2f782cbf97d24f
6:36:53 PM: Fetching cached dependencies
6:36:53 PM: Starting to download cache of 965.5MB
6:37:01 PM: Finished downloading cache in 8.007225114s
6:37:01 PM: Starting to extract cache
6:37:41 PM: Finished extracting cache in 40.008764065s
6:37:41 PM: Finished fetching cache in 48.276314496s
6:37:41 PM: Starting to prepare the repo for build
6:37:41 PM: Preparing Git Reference pull/204/head
6:37:43 PM: Parsing package.json dependencies
6:37:44 PM: Starting build script
6:37:44 PM: Installing dependencies
6:37:44 PM: Python version set to 2.7
6:37:45 PM: Started restoring cached node version
6:37:48 PM: Finished restoring cached node version
6:37:48 PM: Attempting node version '15.14.0' from .nvmrc
6:37:49 PM: v15.14.0 is already installed.
6:37:50 PM: Now using node v15.14.0 (npm v7.7.6)
6:37:50 PM: Started restoring cached build plugins
6:37:50 PM: Finished restoring cached build plugins
6:37:50 PM: Attempting ruby version 2.6.2, read from environment
6:37:52 PM: Using ruby version 2.6.2
6:37:52 PM: Using PHP version 5.6
6:37:52 PM: Started restoring cached yarn cache
6:38:07 PM: Finished restoring cached yarn cache
6:38:07 PM: No yarn workspaces detected
6:38:07 PM: Started restoring cached node modules
6:38:07 PM: Finished restoring cached node modules
6:38:08 PM: Installing NPM modules using Yarn version 1.17.0
6:38:08 PM: yarn install v1.17.0
6:38:09 PM: [1/4] Resolving packages...
6:38:10 PM: [2/4] Fetching packages...
6:38:42 PM: info [email protected]: The platform "linux" is incompatible with this module.
6:38:42 PM: info "[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation.
6:38:42 PM: info @netlify/[email protected]: The platform "linux" is incompatible with this module.
6:38:42 PM: info "@netlify/[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation.
6:38:42 PM: info @netlify/[email protected]: The CPU architecture "x64" is incompatible with this module.
6:38:42 PM: info @netlify/[email protected]: The platform "linux" is incompatible with this module.
6:38:42 PM: info "@netlify/[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation.
6:38:42 PM: info @netlify/[email protected]: The platform "linux" is incompatible with this module.
6:38:42 PM: info "@netlify/[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation.
6:38:42 PM: info @netlify/[email protected]: The CPU architecture "x64" is incompatible with this module.
6:38:42 PM: info @netlify/[email protected]: The platform "linux" is incompatible with this module.
6:38:42 PM: info "@netlify/[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation.
6:38:42 PM: info @netlify/[email protected]: The CPU architecture "x64" is incompatible with this module.
6:38:42 PM: info "@netlify/[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation.
6:38:42 PM: info @netlify/[email protected]: The CPU architecture "x64" is incompatible with this module.
6:38:42 PM: info "@netlify/[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation.
6:38:42 PM: info @netlify/[email protected]: The CPU architecture "x64" is incompatible with this module.
6:38:42 PM: info "@netlify/[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation.
6:38:42 PM: info @netlify/[email protected]: The CPU architecture "x64" is incompatible with this module.
6:38:42 PM: info "@netlify/[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation.
6:38:42 PM: info @netlify/[email protected]: The platform "linux" is incompatible with this module.
6:38:42 PM: info "@netlify/[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation.
6:38:42 PM: info @netlify/[email protected]: The platform "linux" is incompatible with this module.
6:38:42 PM: info "@netlify/[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation.
6:38:42 PM: info @netlify/[email protected]: The CPU architecture "x64" is incompatible with this module.
6:38:42 PM: info @netlify/[email protected]: The platform "linux" is incompatible with this module.
6:38:42 PM: info "@netlify/[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation.
6:38:42 PM: info @netlify/[email protected]: The platform "linux" is incompatible with this module.
6:38:42 PM: info "@netlify/[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation.
6:38:42 PM: info @netlify/[email protected]: The CPU architecture "x64" is incompatible with this module.
6:38:42 PM: info @netlify/[email protected]: The platform "linux" is incompatible with this module.
6:38:42 PM: info "@netlify/[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation.
6:38:42 PM: info @netlify/[email protected]: The platform "linux" is incompatible with this module.
6:38:42 PM: info "@netlify/[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation.
6:38:42 PM: [3/4] Linking dependencies...
6:38:42 PM: warning "@apollo/react-hooks > @apollo/[email protected]" has unmet peer dependency "graphql@^14.0.0 || ^15.0.0".
6:38:42 PM: warning "@apollo/react-hooks > @apollo/client > @graphql-typed-document-node/[email protected]" has unmet peer dependency "graphql@^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0".
6:38:42 PM: warning "apollo-boost > [email protected]" has unmet peer dependency "graphql@^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0".
6:38:42 PM: warning " > @bugsnag/[email protected]" has unmet peer dependency "@bugsnag/core@^7.0.0".
6:38:42 PM: warning " > @jagi/[email protected]" has unmet peer dependency "graphql-tag@^2.10.0".
6:38:42 PM: warning " > [email protected]" has unmet peer dependency "graphql@^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0".
6:38:42 PM: warning "apollo-boost > [email protected]" has unmet peer dependency "graphql@^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0".
6:38:42 PM: warning "apollo-boost > [email protected]" has unmet peer dependency "graphql@^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0".
6:38:42 PM: warning "apollo-boost > [email protected]" has unmet peer dependency "graphql@^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0".
6:38:42 PM: warning "apollo-boost > [email protected]" has unmet peer dependency "graphql@^0.11.3 || ^0.12.3 || ^0.13.0 || ^14.0.0 || ^15.0.0".
6:38:42 PM: warning "apollo-boost > [email protected]" has unmet peer dependency "graphql@^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0".
6:38:42 PM: warning "apollo-boost > apollo-cache > [email protected]" has unmet peer dependency "graphql@^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0".
6:38:42 PM: warning "apollo-boost > apollo-link-error > [email protected]" has unmet peer dependency "graphql@^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0".
6:38:42 PM: warning " > [email protected]" has unmet peer dependency "@babel/core@^7.11.6".
6:38:42 PM: warning " > [email protected]" has unmet peer dependency "core-js@^3.0.0".
6:38:42 PM: warning "gatsby > [email protected]" has unmet peer dependency "babel-eslint@^10.0.0".
6:38:42 PM: warning "gatsby > @typescript-eslint/eslint-plugin > [email protected]" has unmet peer dependency "typescript@>=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta".
6:38:42 PM: warning "gatsby-source-graphql > @graphql-tools/[email protected]" has unmet peer dependency "graphql@^14.0.0 || ^15.0.0".
6:38:42 PM: warning "gatsby > eslint-plugin-graphql > graphql-config > @endemolshinegroup/cosmiconfig-typescript-loader > [email protected]" has unmet peer dependency "typescript@>=2.7".
6:38:42 PM: warning "gatsby-source-graphql > @graphql-tools/links > @graphql-tools/[email protected]" has unmet peer dependency "graphql@^14.0.0 || ^15.0.0".
6:38:42 PM: warning "gatsby-source-graphql > @graphql-tools/[email protected]" has unmet peer dependency "graphql@^14.0.0 || ^15.0.0".
6:38:42 PM: warning " > [email protected]" has unmet peer dependency "@babel/core@^7.12.3".
6:38:42 PM: warning " > [email protected]" has unmet peer dependency "sass@^1.30.0".
6:38:42 PM: warning "gatsby-plugin-sass > [email protected]" has unmet peer dependency "webpack@^4.36.0 || ^5.0.0".
6:38:42 PM: warning "gatsby-source-graphql > @graphql-tools/[email protected]" has unmet peer dependency "@apollo/client@~3.2.5 || ~3.3.0".
6:38:42 PM: warning "gatsby-source-graphql > @graphql-tools/[email protected]" has unmet peer dependency "graphql@^14.0.0 || ^15.0.0".
6:38:42 PM: warning "gatsby-source-graphql > @graphql-tools/links > [email protected]" has unmet peer dependency "graphql@14 - 15".
6:38:42 PM: warning " > [email protected]" has unmet peer dependency "@babel/core@^7.8.0".
6:38:42 PM: warning "babel-jest > [email protected]" has unmet peer dependency "@babel/core@^7.0.0".
6:38:42 PM: warning "babel-jest > babel-preset-jest > [email protected]" has unmet peer dependency "@babel/core@^7.0.0".
6:38:42 PM: warning "babel-jest > babel-preset-jest > babel-preset-current-node-syntax > @babel/[email protected]" has unmet peer dependency "@babel/core@^7.0.0-0".
6:38:42 PM: warning "babel-jest > babel-preset-jest > babel-preset-current-node-syntax > @babel/[email protected]" has unmet peer dependency "@babel/core@^7.0.0-0".
6:38:42 PM: warning " > [email protected]" has unmet peer dependency "eslint-plugin-import@>=1.4.0".
6:39:04 PM: [4/4] Building fresh packages...
6:39:18 PM: Done in 69.33s.
6:39:18 PM: NPM modules installed using Yarn
6:39:18 PM: Started restoring cached go cache
6:39:20 PM: Finished restoring cached go cache
6:39:20 PM: Installing Go version 1.12
6:39:20 PM: unset GOOS;
6:39:20 PM: unset GOARCH;
6:39:20 PM: export GOROOT='/opt/buildhome/.gimme_cache/versions/go1.12.linux.amd64';
6:39:20 PM: export PATH="/opt/buildhome/.gimme_cache/versions/go1.12.linux.amd64/bin:${PATH}";
6:39:20 PM: go version >&2;
6:39:20 PM: export GIMME_ENV='/opt/buildhome/.gimme_cache/env/go1.12.linux.amd64.env';
6:39:20 PM: go version go1.12 linux/amd64
6:39:20 PM: Installing missing commands
6:39:20 PM: Verify run directory
6:39:22 PM: ​
6:39:22 PM: ────────────────────────────────────────────────────────────────
6:39:22 PM:   Netlify Build                                                 
6:39:22 PM: ────────────────────────────────────────────────────────────────
6:39:22 PM: ​
6:39:22 PM: ❯ Version
6:39:22 PM:   @netlify/build 18.17.2
6:39:22 PM: ​
6:39:22 PM: ❯ Flags
6:39:22 PM:   baseRelDir: true
6:39:22 PM:   buildId: 616ca582432ee70007ec7531
6:39:22 PM:   deployId: 616ca582432ee70007ec7533
6:39:22 PM: ​
6:39:22 PM: ❯ Current directory
6:39:22 PM:   /opt/build/repo
6:39:22 PM: ​
6:39:22 PM: ❯ Config file
6:39:22 PM:   /opt/build/repo/netlify.toml
6:39:22 PM: ​
6:39:22 PM: ❯ Context
6:39:22 PM:   deploy-preview
6:39:23 PM: ​
6:39:23 PM: ❯ Installing plugins
6:39:23 PM:    - @netlify/[email protected]
6:39:32 PM: ​
6:39:32 PM: ❯ Loading plugins
6:39:32 PM:    - @netlify/[email protected] from Netlify app
6:39:33 PM: ​
6:39:33 PM: ────────────────────────────────────────────────────────────────
6:39:33 PM:   1. @netlify/plugin-gatsby (onPreBuild event)                  
6:39:33 PM: ────────────────────────────────────────────────────────────────
6:39:33 PM: ​
6:39:35 PM: Found a Gatsby cache. We’re about to go FAST. ⚡️
6:39:41 PM: ​
6:39:41 PM: ────────────────────────────────────────────────────────────────
6:39:41 PM:   Plugin "@netlify/plugin-gatsby" failed                        
6:39:41 PM: ────────────────────────────────────────────────────────────────
6:39:41 PM: ​
6:39:41 PM:   Error message
6:39:41 PM:   Error: Could not load gatsby-config.js
6:39:41 PM:   Missing binding /opt/build/repo/node_modules/node-sass/vendor/linux-x64-72/binding.node
6:39:41 PM:   Node Sass could not find a binding for your current environment: Linux 64-bit with Node.js 12.x
6:39:41 PM: ​
6:39:41 PM:   Found bindings for the following environments:
6:39:41 PM:     - Linux 64-bit with Node.js 15.x
6:39:41 PM: ​
6:39:41 PM:   This usually happens because your environment has changed since running `npm install`.
6:39:41 PM:   Run `npm rebuild node-sass` to download the binding for your current environment.
6:39:41 PM: ​
6:39:41 PM:   Plugin details
6:39:41 PM:   Package:        @netlify/plugin-gatsby
6:39:41 PM:   Version:        1.0.3
6:39:41 PM:   Repository:     git+https://github.com/netlify/netlify-plugin-gatsby.git
6:39:41 PM:   npm link:       https://www.npmjs.com/package/@netlify/plugin-gatsby
6:39:41 PM:   Report issues:  https://github.com/netlify/netlify-plugin-gatsby/issues
6:39:41 PM: ​
6:39:41 PM:   Error location
6:39:41 PM:   In "onPreBuild" event in "@netlify/plugin-gatsby" from Netlify app
6:39:41 PM:       at module.exports (/node_modules/node-sass/lib/binding.js:15:13)
6:39:41 PM: ​
6:39:41 PM:   Resolved config
6:39:41 PM:   build:
6:39:41 PM:     command: npm run build:production
6:39:41 PM:     commandOrigin: ui
6:39:41 PM:     environment:
6:39:41 PM:       - BUTTONDOWN_API_KEY
6:39:41 PM:       - CCN_ENDPOINT
6:39:41 PM:       - GATSBY_BUGSNAG_API_KEY
6:39:41 PM:       - GATSBY_SHOPIFY_TOKEN
6:39:41 PM:       - GRAPHQL_SECRET
6:39:41 PM:       - GRAPHQL_SECRETKEY
6:39:41 PM:       - GRAPHQL_URL
6:39:41 PM:       - GS_COVID_ID
6:39:41 PM:       - GS_PRIVATE_EMAIL
6:39:41 PM:       - GS_PRIVATE_KEY
6:39:41 PM:       - GS_PRIVATE_KEY_ID
6:39:41 PM:       - GS_REGISTRATIONPERM_ID
6:39:41 PM:       - GS_REGISTRATION_ID
6:39:41 PM:       - GTAG_ID
6:39:41 PM:       - HASURA_GRAPHQL_ADMIN_SECRET
6:39:41 PM:       - PERCY_TOKEN
6:39:41 PM:       - REVIEW_ID
6:39:41 PM:       - RO_ENDPOINT
6:39:41 PM:       - RWGPS_API_KEY
6:39:41 PM:       - SENDGRID_API_KEY
6:39:41 PM:       - SLACK_REGISTRATION_WEBHOOK
6:39:41 PM:     publish: /opt/build/repo/public
6:39:41 PM:     publishOrigin: ui
6:39:41 PM:   functionsDirectory: /opt/build/repo/functions
6:39:41 PM:   plugins:
6:39:41 PM:     - inputs: {}
6:39:41 PM:       origin: ui
6:39:41 PM:       package: '@netlify/plugin-gatsby'
6:39:41 PM:   redirects:
6:39:41 PM:     - from: /covid
6:39:41 PM:       status: 301
6:39:41 PM:       to: /registration/covid
6:39:41 PM:     - from: /register
6:39:41 PM:       status: 301
6:39:41 PM:       to: /registration
6:39:41 PM:   redirectsOrigin: config
6:39:41 PM: Caching artifacts
6:39:41 PM: Started saving node modules
6:39:41 PM: Finished saving node modules
6:39:41 PM: Started saving build plugins
6:39:41 PM: Finished saving build plugins
6:39:41 PM: Started saving yarn cache
6:40:03 PM: Finished saving yarn cache
6:40:03 PM: Started saving pip cache
6:40:03 PM: Finished saving pip cache
6:40:03 PM: Started saving emacs cask dependencies
6:40:03 PM: Finished saving emacs cask dependencies
6:40:03 PM: Started saving maven dependencies
6:40:03 PM: Finished saving maven dependencies
6:40:03 PM: Started saving boot dependencies
6:40:03 PM: Finished saving boot dependencies
6:40:03 PM: Started saving rust rustup cache
6:40:03 PM: Finished saving rust rustup cache
6:40:03 PM: Started saving go dependencies
6:40:05 PM: Finished saving go dependencies
6:40:05 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
6:40:05 PM: Creating deploy upload records
6:40:05 PM: Failing build: Failed to build site
6:40:05 PM: Failed during stage 'building site': Build script returned non-zero exit code: 2
6:40:05 PM: Finished processing build request in 3m12.559617364s

Can you submit a pull request?

Yes! I'll need help knowing what to change, but happy to lend a hand.

Thanks for the hard work!

Failure to deploy when importing dotenv using ESM syntax

Describe the bug

My site deployed fine when using the old, now deprecated, Gatsby cache Netlify plugin. I uninstalled this plugin and installed the essential gatsby plugin but my build no longer succeeds.

I suspect it is because I am using ES Modules instead of CommonJS. I am importing dotenv in my gatsby-config.js file and when building, I receive the following error:

Plugin "@netlify/plugin-gatsby" failed

/opt/build/repo/gatsby-config.js:1
import dotenv from 'dotenv';
^^^^^^

SyntaxError: Cannot use import statement outside a module

In "onPreBuild" event in "@netlify/plugin-gatsby" from Netlify app
at loadGatsbyFile (/.netlify/plugins/node_modules/@netlify/plugin-gatsby/src/index.js:32:12)
at onPreBuild (/.netlify/plugins/node_modules/@netlify/plugin-gatsby/src/index.js:57:26)

Steps to reproduce

Step-by-step instructions on how to reproduce the behavior.

Example:

  1. In your Gatsby site, update your package.json start script to be "start": "NODE_OPTIONS='-r esm' gatsby develop"
  2. Install dotenv and add an import statement for it to the top of you gatsby-config.js file import dotenv from 'dotenv';

Expected behavior

The build should complete without issue but fails as it cannot import dotenv.

Can you submit a pull request?

No.

Pull requests are welcome! If you would like to help us fix this bug, please
check our contributions guidelines.

SyntaxError: Unexpected token '.' with optional chaining

Describe the bug
Receiving error SyntaxError: Unexpected token '.' during build on code using optional chaining.

Screen Shot 2021-12-09 at 2 15 35 PM

    {
      resolve: 'gatsby-plugin-csv-feed',
      options: {
        // Feeds
        feeds: [
          {
            // Individual feed query
            query: `
              {
                company: sanityCompanyInfo {
                  _rawDescriptionBlock
                }
                inventory: allSanityInventory(
                  filter: {
                    slug: { current: { ne: null } }
                    equipmentCategories: { slug: { current: { ne: null } } }
                    price: { ne: null }
                    mainImage: { asset: { url: { ne: null }} }
                  }
                ) {
                  edges {
                    node {
                      id
                      title
                      stockNumber
                      condition
                      model
                      price
                      specification
                      _rawDescriptionBlock
                      equipmentMake {
                        name
                        _rawDescriptionBlock
                      }
                      modelReference {
                        _rawDescriptionBlock
                      }
                      slug {
                        current
                      }
                      equipmentCategories {
                        slug {
                          current
                        }
                      }
                      mainImage {
                        asset {
                          url
                        }
                      }
                      imageGallery {
                        images {
                          asset {
                            url
                          }
                        }
                      }
                    }
                  }
                }
              }
            `,
            serialize: ({ query: { inventory, company } }) => {
              return inventory.edges.map((edge) => {
                const node = edge.node
                const images =
                  node.imageGallery?.images &&
                  node.imageGallery.images.map((image) => {
                    if (!image.asset.url) {
                      return null
                    } else {
                      return image.asset.url
                    }
                  })
                const specs =
                  node.specification &&
                  JSON.parse(node.specification)
                    .filter((spec) => spec.SpecificationDescription !== '')
                    .map((spec) => {
                      return {
                        label: spec.Parameter.toLowerCase().toTitleCase(),
                        value: spec.SpecificationDescription.toLowerCase().toTitleCase(),
                      }
                    })
                const specsList =
                  specs &&
                  specs.map((spec) => {
                    return `- ${spec.label}: ${spec.value}\n`
                  })

                const description = `${node.title.toLowerCase().toTitleCase()}
                
Price: ${node.price.toLocaleString('en-US', {
                  style: 'currency',
                  currency: 'USD',
                  minimumFractionDigits: 0,
                  maximumFractionDigits: 0,
                })}  

${specsList ? specsList.join('') : ''}

${lib.toPlainText(node._rawDescriptionBlock || [])}

${lib.toPlainText(node.modelReference?._rawDescriptionBlock || [])}

${lib.toPlainText(node.equipmentMake._rawDescriptionBlock || [])}

${lib.toPlainText(company._rawDescriptionBlock || [])}
`

                return {
                  id: node.stockNumber,
                  title: node.title.toLowerCase().toTitleCase(),
                  description: description,
                  availability: 'in stock',
                  condition: node.condition,
                  price: node.price + ' USD',
                  link: `${process.env.URL}/equipment/${node.equipmentCategories.slug.current}/${node.slug.current}`,
                  image_link: node.mainImage.asset.url,
                  brand: node.equipmentMake.name.toLowerCase().toTitleCase(),
                  google_product_category: 1795,
                  fb_product_category: 177,
                  additional_image_link: images || '',
                }
              })
            },
            // Output file
            output: '/fb-inventory-feed.csv',
            // Options to pass to `json2csv` parser for this feed (optional)
            parserOptions: {},
          },
        ],
      },
    }

Steps to reproduce

In using plugin gatsby-plugin-csv-feed you are to serialize for a CSV file to be generated. Within this code, I'm using the optional chaining operator which netlify-plugin-gatsby appears to think is a syntax error.

Add e2e tests that run on deploy preview

As the local functions server now proxies to the gatsby develop server, our wrapper functions are no longer being fully tested. We should add tests where we run ntl deploy --build and run the tests on that.

Plugin does not work for monorepo

Description

There is a Gatsby Kontent packages monorepo containing a development site + a couple of examples. As a part of kontent-ai/gatsby-packages#202 I wanted to use this plugin instead deprecated Gatsby Cache plugin.

Steps to reproduce

  • Fork the repository
  • Register the repo to Netlify with its config (you can substitute dsg-ssr, with navigation/relationships/resolution)
    • Build command yarn build:dsg-ssr
    • Publish directory /examples/dsg-ssr/public
  • Install this plugin

The build failed on (error from example dsg-ssr, but the same if on all examples):

12:07:02 PM: ────────────────────────────────────────────────────────────────
12:07:02 PM:   Dependencies installation error                               
12:07:02 PM: ────────────────────────────────────────────────────────────────
12:07:02 PM: ​
12:07:02 PM:   Error message
12:07:02 PM:   A Netlify Function failed to require one of its dependencies.
12:07:02 PM:   Please make sure it is present in the site's top-level "package.json".
​
12:07:02 PM:   In file "/opt/build/repo/.netlify/functions-internal/__api/__api.js"
12:07:02 PM:   Cannot find module '../../../.cache/functions/manifest.json' from '/opt/build/repo/.netlify/functions-internal/__api'
12:07:02 PM: ​
12:07:02 PM:   Resolved config
12:07:02 PM:   build:
12:07:02 PM:     command: yarn build:dsg-ssr
12:07:02 PM:     commandOrigin: ui
12:07:02 PM:     environment:
12:07:02 PM:       - NODE_VERSION
12:07:02 PM:     publish: /opt/build/repo/examples/dsg-ssr/public
12:07:02 PM:     publishOrigin: ui
12:07:02 PM:   functions:
12:07:02 PM:     __api:
12:07:02 PM:       external_node_modules:
12:07:02 PM:         - msgpackr-extract
12:07:02 PM:       included_files:
12:07:02 PM:         - examples/dsg-ssr/.cache/functions/**

Expected behavior

Build does not fail and DSG and SSG work.

Environment

I might be able to share the netlify project, if you need.

Netlify returns HTTP ERROR 500 on DSG pages

Describe the bug

I wanted to test the compatibility of the latest version of Gatsby with Netlify and followed all the steps in the Gatsby documentation and on this plugin's readme page.

Gatsby functions and my SSR test page are working, but accessing one of the DSG pages throws a 500 error. There is nothing logged to the __dsg function log in the Netlify dashboard.

Debugging locally with "netlify dev", all pages are working as expected.

Steps to reproduce

  1. Create a new Netlify site
  2. Set build image and environment variable as documented on this plugin's readme page
  3. Deploy from this repository: https://github.com/henrik-m/gatsby4
  4. Navigate to https://your-site.netlify.app/dsg/1/

Expected behavior

The rendered page shows up. Which is what happens locally with netlify dev.

Environment

If it helps, my test site on Netlify is https://youthful-fermi-41f243.netlify.app/. (Gets flagged as malicious by Google Chrome, I don't know why. I just created it the other day).

I don't know why non-existent routes return 500's as well and if this is part of the problem. Netlify doesn't seem to provide any logs for this.

Can you submit a pull request?

No. I cannot even see the actual error in the logs.

Environment Variables not available

Describe the bug

Gatsby functions processed with this plugin do not seem to have access to the environment variables specified on the Netlify admin page (settings/deploys#environment). When sending one of the variables to the frontend via JSON, it is 'null'.

Steps to reproduce

  1. Create a new Gatsby function.
  2. Add an environment variable in the Netlify admin.
  3. Use this variable in the function.

Expected behavior

The provided environment variables are available in the Gatsby function (i.e., can be accessed via process.env.VARIABLE_NAME).

Configuration

Not applicable.

Environment

Tested on Netlify directly.

Screenshots

Not applicable.

Can you submit a pull request?

No.

Misconfigured publish dir is not correctly detected

We try to fail the build when the root dir is set as the publish dir. However according to BugSnag quite a few seem to be slipping through, and it means the builds fail with a plugin error when it gets to the point of saving the cache. We should ensure that we are properly normalizing the paths, and ideally use the same check as the cache util uses.

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Rate-Limited

These updates are currently rate-limited. Click on a checkbox below to force their creation now.

  • chore(deps): update navikt/github-app-token-generator digest to a8ae524
  • chore(deps): update actions/add-to-project action to v0.6.1
  • chore(deps): update dependency path-to-regexp to v6.2.2
  • chore(deps): update dependency @netlify/build to ^29.41.2
  • chore(deps): update dependency typescript to v5.4.5
  • chore(deps): update react monorepo to v18.3.1 (react, react-dom)
  • chore(deps): update actions/add-to-project action to v1
  • chore(deps): update dependency ava to v6
  • chore(deps): update dependency husky to v9
  • chore(deps): update dependency npm-run-all2 to v6
  • chore(deps): update googlecloudplatform/release-please-action action to v4
  • chore(deps): update tibdex/github-app-token action to v2
  • 🔐 Create all rate-limited PRs at once 🔐

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

github-actions
.github/workflows/add-to-project.yml
  • tibdex/github-app-token v1.9.0
  • actions/add-to-project v0.6.0
.github/workflows/add-zenhub-label.yml
  • actions/github-script v6
.github/workflows/fossa.yml
  • actions/checkout v3
.github/workflows/labeler.yml
  • netlify/pr-labeler-action v1.1.0
.github/workflows/pre-release.yml
  • actions/checkout v3
  • actions/setup-node v3
.github/workflows/release-please.yml
  • navikt/github-app-token-generator a3831f44404199df32d8f39f7c0ad9bb8fa18b1c
  • GoogleCloudPlatform/release-please-action v3
  • actions/checkout v3
  • actions/setup-node v2
  • netlify/submit-build-plugin-action v1
.github/workflows/test.yml
  • actions/checkout v3
  • actions/setup-node v3
  • actions/cache v3
  • actions/cache v3
  • actions/checkout v3
  • actions/setup-node v3
  • actions/cache v3
  • actions/cache v3
npm
demo-v5/package.json
  • @sindresorhus/slugify ^1.1.2
  • react ^18.0.0
  • react-dom ^18.0.0
  • co-body ^6.1.0
  • cookie ^0.6.0
  • form-data ^4.0.0
  • fs-extra ^10.0.0
  • gatsby-plugin-netlify ^5.1.0
  • jest ^29.0.0
  • linkfs ^2.1.0
  • multer ^1.4.5-lts.1
  • node-fetch ^2.6.1
  • npm-run-all2 ^5.0.0
  • path-to-regexp ^6.0.0
  • start-server-and-test ^2.0.0
  • node >=18.0.0
demo/package.json
  • @sindresorhus/slugify ^1.1.2
  • gatsby ^4.24.8
  • gatsby-plugin-image ^2.25.0
  • gatsby-plugin-sharp ^4.25.0
  • gatsby-source-filesystem ^4.24.0
  • gatsby-transformer-remark ^5.24.0
  • react ^18.0.0
  • react-dom ^18.0.0
  • co-body ^6.1.0
  • cookie ^0.6.0
  • form-data ^4.0.0
  • fs-extra ^10.0.0
  • gatsby-plugin-netlify ^5.0.0
  • jest ^29.0.0
  • linkfs ^2.1.0
  • multer ^1.4.5-lts.1
  • node-fetch ^2.6.1
  • npm-run-all2 ^5.0.0
  • path-to-regexp ^6.0.0
  • start-server-and-test ^2.0.0
  • node >=14.17.0
package.json
  • @netlify/build ^29.36.1
  • @netlify/eslint-config-node 7.0.1
  • @types/jest ^29.0.0
  • ava ^5.0.0
  • cross-env ^7.0.2
  • husky ^8.0.0
  • jest ^29.0.0
  • ts-jest ^29.0.0
  • execa ^5.0.0
plugin/package.json
  • @netlify/functions ^1.6.0
  • @netlify/ipx ^1.4.6
  • abortcontroller-polyfill ^1.7.3
  • chalk ^4.1.2
  • co-body ^6.1.0
  • cookie ^0.6.0
  • etag ^1.8.1
  • fs-extra ^10.0.0
  • linkfs ^2.1.0
  • multer ^1.4.5-lts.1
  • node-fetch ^2.6.1
  • node-stream-zip ^1.15.0
  • pathe ^0.3.0
  • pretty-bytes ^5.6.0
  • semver ^7.3.5
  • statuses ^2.0.1
  • uuid ^9.0.0
  • @gatsbyjs/reach-router ^2.0.0
  • @netlify/build ^29.36.1
  • @types/chance ^1.1.3
  • @types/fs-extra ^9.0.12
  • @types/multer ^1.4.7
  • @types/semver ^7.3.9
  • chance ^1.1.8
  • execa ^5.0.0
  • gatsby ^5.2.0
  • npm-run-all2 ^5.0.0
  • react ^18.2.0
  • rimraf ^5.0.0
  • tmp-promise ^3.0.3
  • typescript ^5.0.0
  • @gatsbyjs/reach-router *
  • common-tags ^1.8.2
  • node >=14.17.0
nvm
demo-v5/.nvmrc
demo/.nvmrc

  • Check this box to trigger a request for Renovate to run again on this repository

Can't overwrite environment variables set in Netlify UI

Thanks for reporting this bug!

If this is related to a typo or the documentation being unclear, please click on
the relevant page's Edit button (pencil icon) and suggest a correction
instead.

Please search other issues to make sure this bug has not already been reported.

Then fill in the sections below.

Describe the bug

With this build plugin enabled, I am no longer able to overwrite environment variables that are set in the netlify UI. We have two variables, one called ENVKEY and another called ENVKEY_DEV. We have been using build contexts and branch names to determine when we might be in a situation to swap one for the other, at which point we do process.env.ENVKEY = process.env.ENVKEY_DEV. With this build plugin enabled, this operation no longer works, and the original value is retained.

Steps to reproduce

  1. Set two secrets in the Netlify UI
  2. Place the following lines somewhere near the beginning of your build command:
process.env.KEY_1 = process.env.KEY_2
console.log( process.env.KEY_1 )

Expected behavior

process.env.KEY_1 should now have the value from process.env.KEY_2, but it does not.

Configuration

We are running gulp build && gatsby build for our build command, ( gulp is for processing our functions ), but I don't think it really matters what command is being run. We are using dotenv in both gulp and gatsby, with this command:

require( `dotenv` ).config({
  path: `.env`,
})

Environment

This only happens when building on Netlify's build system. Locally, it works as expected.

Screenshots

In the screenshot below, the end of the highlighted line should say develop, not production:
image

Can you submit a pull request?

No.

Static HTML page doesn't update on deploy when data changes

Hello there,
I have a problem with this plugin, that static generated HTML page which loads as a first has cached old data. I am using Shopify as a source of data and I have set deploy to trigger on product create/update/deletion. So for example first second or 2 shows old list of products and then, when React hydrates, new list is loaded. When I clear cache in Netlify or when I update code with something on list page, new static site is generated. Is there any way to prevent static HTML sites to be cached via this plugin or to be regenerated when source data changes?

[security] Enforce Branch Protections

This is an issue generated by (for-internal-use-only)github-tools

Description

This repository has exceeded the development grace period, and the repo owner must decide if branch protections should be enforced.
If this repository houses code used in production in any capacity, branch protections must be enforced. Read (for-internal-use-only)here for more details

What do I need to do?

  • You can control whether or not branch protections are enforced by exclusively creating either of the labels:
    'enforce-branch-protections: true' or 'enforce-branch-protections: false'
  • If there is no branch protection control label, this issue will be recreated.
  • Once you have created either label, you can close this issue.
  • If you have issues or questions, please reach out to #internal-security-n-compliance on slack.

Add support for `res.cookie`

res.cookie works in gatsby (eg. res.cookie("test", true, { httpOnly: false }) but does not work on netlify

Steps to reproduce

create a function that set a cookie eg.

export default function handler(req, res) {
  res.cookie("test", true, { httpOnly: false })
  res.redirect("/")
}

Expected behavior

runs and sets cookie locally.
on netlify the function is erroring with

Error when executing function "my-function.js": "res.cookie is not a function"

Can you submit a pull request?

Yes

Gatsby 4 functions not working when building from cli

I am expirimenting with Gatsby 4 for my site https://autokopenduitsland.netlify.app/ using @netlify/[email protected] 3 functions are added, for example for DSG.

When using the Netlify builders, I got everything working. DSG functions render my defer-ed pages and I can see logging in the DSG function.

But when building from another source, for example using netlify-cli locally and using netlify build and netlify deploy, the Functions are added, but they do not seem to work. Nothing happens in the logs and I get 404s.

Built from Netlify services: https://6164218fb2b760e7633aae59--autokopenduitsland.netlify.app/een-auto-importeren-uit-duitsland
Built and deployed from local machine using netlify-cli: https://6164208c6ff98275dadbf5b9--autokopenduitsland.netlify.app/een-auto-importeren-uit-duitsland

Is it redirect rules? The UI gives me:
2 redirect rules processed vs 1 redirect rule processed
manually adding redirect rule /* /.netlify/functions/__dsg 200 makes the page error ENOENT: no such file or directory, lstat '/var/task/.cache/data'": https://61642c784e749892dcf79988--autokopenduitsland.netlify.app/een-auto-importeren-uit-duitsland

table of contents is wrong

Table of contents includes links from another plugin, and doesn't match up to the headings that exist

Not able to build nor deploy gatsby site

I have one gatsby site built with the version 2.32.11 of gatsby and deployed on netlify. Today I decided to push some updates, but it fails in the onPreBuild process.

Describe the bug

I have installed the v1 of @netlify/plugin-gatsby, following these instructions.

My netlify.toml looks like this:

[build]
command = "npm run build"
publish = "public/"

[[plugins]]
package = "@netlify/plugin-gatsby"

[build.environment]
NODE_VERSION = '14.0.0'

This is how

But when the deeply runs, it fails. Here is the log:

10:46:57 PM: Build ready to start
10:46:59 PM: build-image version: c6001ed68662a13e5deb24abec2b46058c58248a
10:46:59 PM: build-image tag: v3.9.0
10:46:59 PM: buildbot version: f650485c830eb31597911322420b99299a4303b8
10:46:59 PM: Fetching cached dependencies
10:46:59 PM: Failed to fetch cache, continuing with build
10:46:59 PM: Starting to prepare the repo for build
10:47:00 PM: No cached dependencies found. Cloning fresh repo
10:47:00 PM: git clone https://github.com/sk8Guerra/cicerone
10:47:04 PM: Preparing Git Reference refs/heads/master
10:47:05 PM: Parsing package.json dependencies
10:47:05 PM: Different publish path detected, going to use the one specified in the Netlify configuration file: 'public' versus 'public/' in the Netlify UI
10:47:05 PM: Different build command detected, going to use the one specified in the Netlify configuration file: 'npm run build' versus 'gatsby build' in the Netlify UI
10:47:05 PM: Starting build script
10:47:06 PM: Installing dependencies
10:47:06 PM: Python version set to 2.7
10:47:07 PM: Downloading and installing node v14.0.0...
10:47:07 PM: Downloading https://nodejs.org/dist/v14.0.0/node-v14.0.0-linux-x64.tar.xz...
10:47:07 PM: Computing checksum with sha256sum
10:47:08 PM: Checksums matched!
10:47:11 PM: Now using node v14.0.0 (npm v6.14.4)
10:47:11 PM: Started restoring cached build plugins
10:47:11 PM: Finished restoring cached build plugins
10:47:11 PM: Attempting ruby version 2.7.2, read from environment
10:47:12 PM: Using ruby version 2.7.2
10:47:13 PM: Using PHP version 5.6
10:47:13 PM: Started restoring cached node modules
10:47:13 PM: Finished restoring cached node modules
10:47:13 PM: Installing NPM modules using NPM version 6.14.4
10:47:28 PM: npm WARN Invalid name: "Cicerone | El blog políglota"
10:47:28 PM: npm WARN repo No description
10:47:28 PM: npm WARN repo No repository field.
10:47:28 PM: npm WARN repo No README data
10:47:28 PM: npm WARN repo No license field.
10:47:28 PM: added 28 packages from 16 contributors in 14.11s
10:47:28 PM: found 0 vulnerabilities
10:47:28 PM: NPM modules installed
10:47:28 PM: Started restoring cached go cache
10:47:28 PM: Finished restoring cached go cache
10:47:28 PM: go version go1.14.4 linux/amd64
10:47:28 PM: go version go1.14.4 linux/amd64
10:47:28 PM: Installing missing commands
10:47:28 PM: Verify run directory
10:47:30 PM: ​
10:47:30 PM: ────────────────────────────────────────────────────────────────
10:47:30 PM:   Netlify Build                                                 
10:47:30 PM: ────────────────────────────────────────────────────────────────
10:47:30 PM: ​
10:47:30 PM: ❯ Version
10:47:30 PM:   @netlify/build 18.13.1
10:47:30 PM: ​
10:47:30 PM: ❯ Flags
10:47:30 PM:   baseRelDir: true
10:47:30 PM:   buildId: 61529e41dae8cf0007003b4b
10:47:30 PM:   deployId: 61529e41dae8cf0007003b4d
10:47:30 PM: ​
10:47:30 PM: ❯ Current directory
10:47:30 PM:   /opt/build/repo
10:47:30 PM: ​
10:47:30 PM: ❯ Config file
10:47:30 PM:   /opt/build/repo/netlify.toml
10:47:30 PM: ​
10:47:30 PM: ❯ Context
10:47:30 PM:   production
10:47:30 PM: ​
10:47:30 PM: ❯ Installing plugins
10:47:30 PM:    - @netlify/[email protected]
10:47:42 PM: ​
10:47:42 PM: ❯ Loading plugins
10:47:42 PM:    - @netlify/[email protected] from netlify.toml
10:47:42 PM: ​
10:47:42 PM: ────────────────────────────────────────────────────────────────
10:47:42 PM:   1. onPreBuild command from @netlify/plugin-gatsby             
10:47:42 PM: ────────────────────────────────────────────────────────────────
10:47:42 PM: ​
10:47:42 PM: No Gatsby cache found. Building fresh.
10:47:42 PM: ​
10:47:42 PM: ────────────────────────────────────────────────────────────────
10:47:42 PM:   Plugin "@netlify/plugin-gatsby" failed                        
10:47:42 PM: ────────────────────────────────────────────────────────────────
10:47:42 PM: ​
10:47:42 PM:   Error message
10:47:42 PM:   Error: Could not load gatsby-config.js
10:47:42 PM:   Cannot find module 'dotenv'
10:47:42 PM:   Require stack:
10:47:42 PM:   - /opt/build/repo/gatsby-config.js
10:47:42 PM:   - /opt/build/repo/.netlify/plugins/node_modules/@netlify/plugin-gatsby/src/index.js
10:47:42 PM:   - /opt/buildhome/.netlify-build-nvm/versions/node/v12.22.6/lib/node_modules/@netlify/build/src/plugins/child/logic.js
10:47:42 PM:   - /opt/buildhome/.netlify-build-nvm/versions/node/v12.22.6/lib/node_modules/@netlify/build/src/plugins/child/load.js
10:47:42 PM:   - /opt/buildhome/.netlify-build-nvm/versions/node/v12.22.6/lib/node_modules/@netlify/build/src/plugins/child/main.js
10:47:42 PM: ​
10:47:42 PM:   Plugin details
10:47:42 PM:   Package:        @netlify/plugin-gatsby
10:47:42 PM:   Version:        1.0.3
10:47:42 PM:   Repository:     git+https://github.com/netlify/netlify-plugin-gatsby.git
10:47:42 PM:   npm link:       https://www.npmjs.com/package/@netlify/plugin-gatsby
10:47:42 PM:   Report issues:  https://github.com/netlify/netlify-plugin-gatsby/issues
10:47:42 PM: ​
10:47:42 PM:   Error location
10:47:42 PM:   In "onPreBuild" event in "@netlify/plugin-gatsby" from netlify.toml
10:47:42 PM: ​
10:47:42 PM:   Resolved config
10:47:42 PM:   build:
10:47:42 PM:     command: npm run build
10:47:42 PM:     commandOrigin: config
10:47:42 PM:     environment:
10:47:42 PM:       - CLIENT_KEY
10:47:42 PM:       - FAUNA_URL
10:47:42 PM:       - NODE_VERSION
10:47:42 PM:       - SERVER_KEY
10:47:42 PM:       - TRACKING_ID
10:47:42 PM:     publish: /opt/build/repo/public
10:47:42 PM:     publishOrigin: config
10:47:42 PM:   plugins:
10:47:42 PM:     - inputs: {}
10:47:42 PM:       origin: config
10:47:42 PM:       package: '@netlify/plugin-gatsby'
10:47:43 PM: Caching artifacts
10:47:43 PM: Started saving node modules
10:47:43 PM: Finished saving node modules
10:47:43 PM: Started saving build plugins
10:47:43 PM: Finished saving build plugins
10:47:43 PM: Started saving pip cache
10:47:43 PM: Finished saving pip cache
10:47:43 PM: Started saving emacs cask dependencies
10:47:43 PM: Finished saving emacs cask dependencies
10:47:43 PM: Started saving maven dependencies
10:47:43 PM: Finished saving maven dependencies
10:47:43 PM: Started saving boot dependencies
10:47:43 PM: Finished saving boot dependencies
10:47:43 PM: Started saving rust rustup cache
10:47:43 PM: Finished saving rust rustup cache
10:47:43 PM: Started saving go dependencies
10:47:43 PM: Finished saving go dependencies
10:47:46 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
10:47:46 PM: Creating deploy upload records
10:47:46 PM: Failing build: Failed to build site
10:47:46 PM: Failed during stage 'building site': Build script returned non-zero exit code: 2
10:47:46 PM: Finished processing build request in 47.545987711s

Screenshots

Screen Shot 2021-09-28 at 09 52 39

Expected behavior

The site to be successfully built and deployed.

Can you submit a pull request?

No.

ChainAlert: npm package release (2.0.1) has no matching tag in this repo

Dear @netlify/plugin-gatsby maintainers,
Thank you for your contribution to the open-source community.

This issue was automatically created to inform you a new version (2.0.1) of @netlify/plugin-gatsby was published without a matching tag in this repo.

Our service monitors the open-source ecosystem and informs popular packages' owners in case of potentially harmful activity.
If you find this behavior legitimate, kindly close and ignore this issue. Read more

badge

Use `utils.functions.add()`

utils.functions.add(path) can be used to copy a file or directory to the Functions source directory (such as netlify/functions/).

This plugin currently uses fs.copy() and constants.FUNCTIONS_SRC which works as well. However, using utils.functions.add() provides with some abstraction which will be helpful if we change some details on how Functions are configured in the future, such as providing a plugin-specific Functions directory as suggested in https://github.com/netlify/pod-workflow/issues/222

Clear the cache if a build fails

Thanks for suggesting a new feature!

Please fill in the sections below.

Which problem is this feature request solving?

We're getting bad api responses cached, resulting in chains of broken builds. The bad response results in a Gatsby error in gatsby-node's onPostBuild, but the cache saves the build anyways, and then the next build fails because of the cached bad response, and the next, and the next, etc.

I've tried throwing errors inside the build process and running gatsby clean after the build command if there's an error, but that only remove .cache & .public, not whatever's attached to utils.cache.

We're working on upgrading to gatsby v4 to use the newer version, but unless I'm missing something skimming the source it looks like the same behaviour there.

I think the cache should, by default, be cleared if a build fails. We could check for the status code in onPostBuild and utils.cache.remove() if non-zero. No point in saving a bad image, especially if it leads to an endless chain of broken builds requiring manual intervention

New/Custom Gatsby Cache Values Not Working

Thanks for reporting this bug!

If this is related to a typo or the documentation being unclear, please click on
the relevant page's Edit button (pencil icon) and suggest a correction
instead.

Please search other issues to make sure this bug has not already been reported.

Then fill in the sections below.

Describe the bug

In my local build, I'm using the Gatsby API (v3.x) to cache data during the build process. (https://www.gatsbyjs.com/docs/build-caching/)

I see that after a successful build the data is added to the cache. When the subsequent build occurs, the logs say that Netlify/Gatsby found a previous cache. However, the value I set in the cache during the previous build is null.

Any ideas what might not be working or if this use case is supported?

Steps to reproduce

  1. Update Gatsby cache during the createPage and onPostBootstrap lifecycle.
  2. Confirm that build is successful
  3. Build again and debug the cache.
  4. Cache for value added in step #1 is empty/null.

Example:

  1. Type the following command: [...]
  2. etc.

Expected behavior

A clear and concise description of what you expected to happen.

Configuration

Using Gatsby 3.14.6 with the V2 Netlify plugins.

Environment

System:
OS: Linux 5.4 Debian GNU/Linux 10 (buster) 10 (buster)
CPU: (8) x64 Intel(R) Xeon(R) Platinum 8272CL CPU @ 2.60GHz
Shell: 5.0.3 - /bin/bash
Binaries:
Node: 14.18.1 - /usr/local/bin/node
Yarn: 1.22.15 - /usr/bin/yarn
npm: 6.14.15 - /usr/local/bin/npm
Languages:
Python: 2.7.16 - /usr/bin/python

Enter the following command in a terminal and copy/paste its output:

npx envinfo --system --binaries --browsers --npmPackages @netlify/plugin-gatsby

System:
OS: Linux 5.4 Debian GNU/Linux 10 (buster) 10 (buster)
CPU: (8) x64 Intel(R) Xeon(R) Platinum 8272CL CPU @ 2.60GHz
Memory: 1.43 GB / 15.63 GB
Container: Yes
Shell: 5.0.3 - /bin/bash
Binaries:
Node: 14.18.1 - /usr/local/bin/node
Yarn: 1.22.15 - /usr/bin/yarn
npm: 6.14.15 - /usr/local/bin/npm

Screenshots

If applicable, add screenshots to help explain your problem.

Can you submit a pull request?

Maybe.

Pull requests are welcome! If you would like to help us fix this bug, please
check our contributions guidelines.

Gatbsy Functions should be live-reloaded

Because Gatsby Functions are lazily-compiled during gatsby develop we can't import them directly at dev time, and instead copy them all at build time. This is a worse experience than running gatsby develop directly, which recompiles them when they change. We should either proxy all function requests to gatsby develop when running ntl dev, or find a way to get the functions to all build and then load from there.

On fresh install, ENOENT error for `.cache/functions`

Describe the bug

On a fresh install of Gatsby, the plugin fails to build due to a missing .cache/functions directory.

────────────────────────────────────────────────────────────────
  Plugin "@netlify/plugin-gatsby" failed
────────────────────────────────────────────────────────────────

  Error message
  Error: Error message
  ENOENT: no such file or directory, lstat '.cache/functions'

feature: support Node.js 12

Which problem is this feature request solving?

The current minimum supported version for the plugin is Node.js 14:

"node": ">=14.17.0"

Since our default for new sites is Node.js 12 can we support it too?
Not sure if there's a limitation with using 12.

Describe the solution you'd like

Support Node.js 12

Describe alternatives you've considered

Tell users to manually set their sites Node.js version to 14

Can you submit a pull request?

Yes

Add support for image runner

If an the build command is set to gatsby-runner, then add the support for the image handling:

  • Detect gatsby-runner in the build script or build command
  • Mutate the function config to set correct values for builder, included files and external node modules
  • Create the gatsby-image function
  • Add the redirect

[functions] Must use import to load ES Module: node-fetch

Describe the bug

HTTP 502 Bad Gateway error with the following response body:

{
  "errorType": "Error",
  "errorMessage": "Must use import to load ES Module: /var/task/packages/[omitted]/node_modules/node-fetch/src/index.js\nrequire() of ES modules is not supported.\nrequire() of /var/task/packages/[omitted]/node_modules/node-fetch/src/index.js from /var/task/packages/[omitted]/netlify/functions/gatsby/functions.js is an ES module file as it is a .js file whose nearest parent package.json contains \"type\": \"module\" which defines all .js files in that package scope as ES modules.\nInstead rename index.js to end in .cjs, change the requiring code to use import(), or remove \"type\": \"module\" from /var/task/packages/[omitted]/node_modules/node-fetch/package.json.\n",
  "trace": [
    "Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /var/task/packages/[omitted]/node_modules/node-fetch/src/index.js",
    "require() of ES modules is not supported.",
    "require() of /var/task/packages/[omitted]/node_modules/node-fetch/src/index.js from /var/task/packages/[omitted]/netlify/functions/gatsby/functions.js is an ES module file as it is a .js file whose nearest parent package.json contains \"type\": \"module\" which defines all .js files in that package scope as ES modules.",
    "Instead rename index.js to end in .cjs, change the requiring code to use import(), or remove \"type\": \"module\" from /var/task/packages/[omitted]/node_modules/node-fetch/package.json.",
    "",
    "    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1089:13)",
    "    at Module.load (internal/modules/cjs/loader.js:937:32)",
    "    at Function.Module._load (internal/modules/cjs/loader.js:778:12)",
    "    at Module.require (internal/modules/cjs/loader.js:961:19)",
    "    at require (internal/modules/cjs/helpers.js:92:18)",
    "    at Object.<anonymous> (/var/task/packages/[omitted]/netlify/functions/gatsby/functions.js:3:37)",
    "    at Module._compile (internal/modules/cjs/loader.js:1072:14)",
    "    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)",
    "    at Module.load (internal/modules/cjs/loader.js:937:32)",
    "    at Function.Module._load (internal/modules/cjs/loader.js:778:12)"
  ]
}

Steps to reproduce

  • write gatsby function
  • run local netlify build
  • run local netlify deploy
  • observe 502 HTTP error with above response body on hitting /api/xxx endpoint

OR

  • write gatsby function
  • git push
  • use built-in netilfy CI pipeline
  • observe 502 HTTP error with above response body on hitting /api/xxx endpoint

Expected behavior

the function should call the defined gatsby handler without error

Configuration

package.json:

{
  "dependencies": {
    "gatsby": "3.14.0"
  },
  "devDependencies": {
    "@netlify/plugin-gatsby": "1.0.3",
    "gatsby-plugin-netlify": "3.14.0",
    "netlify-cli": "6.9.28"
  }
}

netlify.toml:

[build]
command = "gatsby build"
publish = "public"

[[plugins]]
package = "@netlify/plugin-gatsby"

file structure:

src
-- functions
---- xxx.ts

commands to build/deploy:

$ netlify build
$ netlify deploy --prod
$ curl https://xxx.netlify.app/api/xxx

Can you submit a pull request?

Yes, happy to! Not too sure where to start though, this seems like it's coming from the template.

Plugin cannot find module manifest.json

Ran a clean cache build on Netlify with @netlify/plugin-gatsby installed, and it seems to be getting a dependency error in the Functions building step:

7:30:38 PM:   5. Functions bundling                                         
7:30:38 PM: ────────────────────────────────────────────────────────────────
7:30:38 PM: ​
7:30:38 PM: Packaging Functions from serverless-functions directory:
7:30:38 PM:  - gatsby/gatsby.js
7:30:38 PM:  - pgp-reform-feed/pgp-reform-feed.js
7:30:38 PM: ​
7:30:39 PM: ​
7:30:39 PM: ─────────────────────────────────────────────
7:30:39 PM: ────────────────────────────────────────────────────────────────
7:30:39 PM:   Dependencies installation error                               
7:30:39 PM: ────────────────────────────────────────────────────────────────
7:30:39 PM: ​
7:30:39 PM:   Error message
7:30:39 PM:   A Netlify Function failed to require a local file.
7:30:39 PM:   Please make sure the file exists and its path is correctly spelled.
7:30:39 PM: ​
7:30:39 PM:   In file "/opt/build/repo/serverless-functions/gatsby/gatsby.js"
7:30:39 PM:   Cannot find module '../../../.cache/functions/manifest.json' from '/opt/build/repo/serverless-functions/gatsby'

Not sure I totally understand the purpose of the template/ dir but it looks like this is where things break: https://github.com/netlify/netlify-plugin-gatsby/blob/main/plugin/src/templates/gatsby.js#L11 ?

Steps to reproduce

This was a Netlify build so tough to provide exact steps but I ran gatsby build on my gatsby v3 site.

The plugin seems to have added this to my .gitignore

# Local Netlify folder
.netlify
+# @netlify/plugin-gatsby ignores start
+serverless-functions/gatsby
+# @netlify/plugin-gatsby ignores end

this is my package.json

  "dependencies": {
    "@apollo/react-hooks": "4.0.0",
    "@mdx-js/mdx": "1.5.9",
    "@mdx-js/react": "1.5.8",
    "apollo-boost": "0.4.7",
    "colormap": "^2.3.1",
    "d3": "^6.1.1",
    "dompurify": "2.0.8",
    "firebase": "7.8.2",
    "firebaseui": "4.4.0",
    "gatsby": "^3.7.0",
    "gatsby-cli": "^3.7.0",
    "gatsby-image": "^3.7.0",
    "gatsby-plugin-canonical-urls": "^3.7.0",
    "gatsby-plugin-force-trailing-slashes": "^1.0.4",
    "gatsby-plugin-google-fonts": "^1.0.1",
    "gatsby-plugin-google-gtag": "^3.7.0",
    "gatsby-plugin-manifest": "^3.7.0",
    "gatsby-plugin-mdx": "2.7.0",
    "gatsby-plugin-meta-redirect": "^1.1.1",
    "gatsby-plugin-offline": "^4.7.0",
    "gatsby-plugin-open-graph-images": "^0.1.7",
    "gatsby-plugin-react-helmet": "^4.7.0",
    "gatsby-plugin-react-svg": "3.0.0",
    "gatsby-plugin-robots-txt": "^1.5.3",
    "gatsby-plugin-s3": "^0.3.4",
    "gatsby-plugin-sharp": "^3.7.0",
    "gatsby-remark-embedder": "^5.0.0",
    "gatsby-source-airtable": "^2.1.1",
    "gatsby-source-filesystem": "^3.7.0",
    "gatsby-source-graphql": "3.7.0",
    "gatsby-source-pg": "0.2.1",
    "gatsby-source-rss-feed": "^1.2.0",
    "gatsby-transformer-javascript-frontmatter": "^3.7.0",
    "gatsby-transformer-json": "3.7.0",
    "gatsby-transformer-rehype": "^2.0.0",
    "gatsby-transformer-sharp": "^3.7.0",
    "js-stats": "^1.0.5",
    "moment": "^2.27.0",
    "netlify-cms": "^2.10.51",
    "prop-types": "^15.7.2",
    "react": "^16.12.0",
    "react-aim-menu": "^1.0.12",
    "react-dom": "^16.12.0",
    "react-helmet": "^5.2.1",
    "react-inlinesvg": "1.2.0",
    "react-mailchimp-subscribe": "^2.1.0",
    "react-simple-maps": "^2.1.2",
    "react-svg-tooltip": "^0.0.11",
    "react-transition-group": "https://github.com/reactjs/react-transition-group.git#v1-stable",
    "rehype-slug": "^3.0.0",
    "throttle-debounce": "^2.3.0",
    "victory": "^35.0.8"
  },
  "devDependencies": {
    "@netlify/plugin-gatsby": "^0.0.2",
    "prettier": "^1.19.1"
  },

Expected behavior

Dependency should be found?

Environment

7:23:11 PM: Now using node v12.18.0 (npm v6.14.4)

Remove check to ensure .cache/json folder exists

Thanks for suggesting a new feature!

Please fill in the sections below.

This is not an enhancement, more of a code cleanup.

#124 ensured the .cache/json folder existed, but this appears to no longer be necessary based on the fix in gatsbyjs/gatsby#33431 (merged in October 2021) that resolved gatsbyjs/gatsby#33262.

Describe the solution you'd like

Revert #124 as this check is no longer necessary.

Describe alternatives you've considered

N/A

Can you submit a pull request?

Yes.

Pull requests are welcome! If you would like to help us add this feature, please
check our contributions guidelines.

Error "Module did not self-register" in SSR pages after upgrading to 4.8.0

Yes the site does build however SSR stopped working and I thought maybe this was related.

Now, I'm getting this message when I visit a page with SSR.

{
"errorType": "Error",
"errorMessage": "Module did not self-register: '/var/task/.cache/query-engine/assets/prebuilds/linux-x64/node.abi93.glibc.node'.",
"trace": [
"Error: Module did not self-register: '/var/task/.cache/query-engine/assets/prebuilds/linux-x64/node.abi93.glibc.node'.",
"    at Object.Module._extensions..node (internal/modules/cjs/loader.js:1144:18)",
"    at Module.load (internal/modules/cjs/loader.js:950:32)",
"    at Function.Module._load (internal/modules/cjs/loader.js:790:12)",
"    at Module.require (internal/modules/cjs/loader.js:974:19)",
"    at require (internal/modules/cjs/helpers.js:93:18)",
"    at Object.exports.__esModule (/var/task/.cache/query-engine/index.js:146728:18)",
"    at __webpack_require__ (/var/task/.cache/query-engine/index.js:682628:42)",
"    at Object.<anonymous> (/var/task/.cache/query-engine/index.js:146682:20)",
"    at __webpack_require__ (/var/task/.cache/query-engine/index.js:682628:42)",
"    at Object.defineProperty.value (/var/task/.cache/query-engine/index.js:144176:13)"
]
}

It was working before upgrading Gatsby to v4.8 and it works locally.

Originally posted by @t2ca in #291 (comment)

Intermittent Build Failures at Merge Worker State

Describe the bug

Beginning when I upgraded to Gatsby v4.6 I started getting errors when building on Netlify. Most builds succeed, and then all of a sudden all builds fail. Sometimes clearing the cache fixes it, sometimes not. Now, a content change caused my production deploy to fail twice in a row.

I read that this might have been a regression, so I downgraded to 4.5, which fixed it initially but now build failures are happening again.

Steps to reproduce

Build gatsby site on netlify with v4.5 or v4.6

Expected behavior

A successful build.

Configuration

module.exports = {
flags: {
// FAST_DEV: true,
PRESERVE_FILE_DOWNLOAD_CACHE: true,
PARALLEL_SOURCING: true,
},
plugins: [
gatsby-plugin-react-helmet,
gatsby-plugin-extract-schema,
// {
// resolve: gatsby-plugin-sharp,
// options: { defaults: { placeholder: 'none', quality: 90 } },
// },
// babel-plugin-remove-graphql-queries, // for use with storybook
gatsby-plugin-advanced-sitemap,
// gatsby-plugin-webpack-bundle-analyser-v3,
// gatsby-plugin-preload-link-crossorigin,

// `gatsby-plugin-lint-queries`,
`gatsby-plugin-sharp`,
`babel-plugin-remove-graphql-queries`,
{
  resolve: `gatsby-plugin-feed`,
  options: {
    query: `
    {site {
      siteMetadata {
        title
        description
        siteUrl
        site_url: siteUrl
      }
    }}`,
    feeds: [
      {
        serialize: ({ query: { blog, site } }) => {
          return blog.nodes.map(
            ({ title, date, slug, body, category, author }) => ({
              title: title,
              description: body.childMarkdownRemark.excerpt,
              categories: [category],
              author: author,
              date: date,
              url: site.siteMetadata.siteUrl + '/blog/' + slug,
              guid: site.siteMetadata.siteUrl + '/blog/' + slug,
            })
          )
        },
        query: `
        {
    blog: allContentfulBlogPost(sort: { fields: [date], order: DESC }) {
      nodes {
        title
        category
        author{
          name
        }
        date
        slug
        body {
          childMarkdownRemark {
            excerpt
          }
        }
      }
    }
  }
    `,
        output: '/rss.xml',
        title: 'Blog RSS',
      },
    ],
  },
},
{
  resolve: `gatsby-theme-material-ui`,
  options: {
    webFontsConfig: null,
  },
},
{
  resolve: `gatsby-plugin-anchor-links`,
  options: {
    offset: -150,
  },
},
{
  resolve: 'gatsby-plugin-robots-txt',
  options: {
    sitemap: `${siteUrl}/sitemap/sitemap-pages.xml`,
    resolveEnv: () => CONTEXT,
    env: {
      production: {
        policy: [{ userAgent: '*' }],
      },
      'branch-deploy': {
        policy: [
          { userAgent: '*', disallow: ['/'] },
          { userAgent: 'Algolia Crawler', allow: ['/'] },
        ],
      },
      'deploy-preview': {
        policy: [
          { userAgent: '*', disallow: ['/'] },
          {
            userAgent: 'Algolia Crawler',
            allow: ['/ # Algolia-Crawler-Verif: STRING'],
          },
        ],
      },
    },
  },
},
{
  resolve: 'gatsby-plugin-intercom-spa',
  options: {
    app_id: GATSBY_INTERCOM_APP_ID,
    include_in_development: true,
    delay_timeout: 5000,
  },
},
{
  resolve: `gatsby-plugin-canonical-urls`,
  options: {
    siteUrl,
  },
},
{
  resolve: `gatsby-source-filesystem`,
  options: {
    name: `images`,
    path: `${__dirname}/src/`,
  },
},
{
  resolve: `gatsby-source-filesystem`,
  options: {
    name: `air_docs`,
    path: `${__dirname}/docs/`,
  },
},
{
  resolve: 'gatsby-plugin-react-svg',
  options: {
    rule: {
      include: /assets\/svg/,
    },
  },
},
{
  resolve: `gatsby-transformer-sharp`,
},
{
  resolve: `gatsby-transformer-inline-svg`,
},
{
  resolve: `gatsby-plugin-image`,
},
{
  resolve: `gatsby-plugin-manifest`,
  options: {
     // Details removed for privacy
    cache_busting_mode: 'none',
    crossOrigin: 'anonymous',
  },
},

// this (optional) plugin enables Progressive Web App + Offline functionality
// To learn more, visit: https://gatsby.dev/offline
{
  resolve: `gatsby-plugin-offline`,
},
// `gatsby-plugin-force-trailing-slashes`,
{
  resolve: 'gatsby-source-contentful',
  options: {
    spaceId: CONTENTFUL_SPACE_ID,
    accessToken: ACCESS_TOKEN,
  },
},
{
  resolve: 'gatsby-source-contentful',
  options: {
    spaceId: AIR_CONTENTFUL_SPACE_ID,
    accessToken: AIR_ACCESS_TOKEN,
  },
},
{
  resolve: `gatsby-transformer-remark`,
  options: {
    plugins: [
      {
        resolve: `gatsby-remark-embed-video`,
        options: {
          width: 560,
          height: 315,
          related: false,
          noIframeBorder: true,
        },
      },
      {
        resolve: `gatsby-remark-responsive-iframe`,
      },
      {
        resolve: `gatsby-remark-images-contentful`,
        options: {
          maxWidth: 800,
          withWebp: true,
          linkImagesToOriginal: false,
          sizeByPixelDensity: true,
        },
      },
      {
        resolve: `gatsby-remark-autolink-headers`,
        options: {
          icon: `<svg width="36" height="36" viewBox="0 0 36 36" fill="none" xmlns="http://www.w3.org/2000/svg"> <circle cx="18" cy="18" r="18" fill="white"/> <path fill-rule="evenodd" clip-rule="evenodd" d="M16 23C16 23.6 15.6 24 15 24H12C8.7 24 6 21.3 6 18C6 14.7 8.7 12 12 12H15C15.6 12 16 12.4 16 13C16 13.6 15.6 14 15 14H12C9.8 14 8 15.8 8 18C8 20.2 9.8 22 12 22H15C15.6 22 16 22.4 16 23ZM24 12H21C20.4 12 20 12.4 20 13C20 13.6 20.4 14 21 14H24C26.2 14 28 15.8 28 18C28 20.2 26.2 22 24 22H21C20.4 22 20 22.4 20 23C20 23.6 20.4 24 21 24H24C27.3 24 30 21.3 30 18C30 14.7 27.3 12 24 12ZM14 19C13.4 19 13 18.6 13 18C13 17.4 13.4 17 14 17H22C22.6 17 23 17.4 23 18C23 18.6 22.6 19 22 19H14Z" fill="#363E50"/> </svg>`,
          isIconAfterHeader: true,
          enableCustomId: true,
          elements: ['h1', 'h2', 'h3'],
          offsetY: 100,
        },
      },
      `gatsby-remark-prismjs`,
    ],
  },
},
{
  resolve: 'gatsby-plugin-preconnect',
  options: {
    domains: [
      'https://www.google.com',
      'https://googleads.g.doubleclick.net',
      'https://www.google-analytics.com',
      'https://www.googleadservices.com',
      'https://www.googletagmanager.com',
    ],
  },
},
{
  resolve: `gatsby-plugin-gdpr-cookies`,
  options: {
    googleTagManager: {
      trackingId: TAG_MANAGER_ID,
      cookieName: 'gatsby-gdpr-google-tagmanager',
      defaultDataLayer: { platform: 'gatsby' },
    },
    // only turn on when debugging
    // environments: ['production', 'development'],
  },
},
{
  resolve: `gatsby-plugin-algolia`,
  options: {
    enablePartialUpdates: true,
    appId: process.env.GATSBY_ALGOLIA_APP_ID,
    apiKey: process.env.ALGOLIA_ADMIN_KEY,
    queries,
    chunkSize: 10000, // default: 1000
  },
},
{
  resolve: `gatsby-plugin-netlify`,
  options: {
    headers: {
      '/**/*.html': [
        'cache-control: public',
        'cache-control: max-age=0',
        'cache-control: must-revalidate',
      ],
      '/page-data/*.json': [
        'cache-control: public',
        'cache-control: max-age=0',
        'cache-control: must-revalidate',
      ],
      '/app-data.json': [
        'cache-control: public',
        'cache-control: max-age=0',
        'cache-control: must-revalidate',
      ],
      '/static/*': [
        'cache-control: public',
        'cache-control: max-age=31536000',
        'cache-control: immutable',
      ],
      '/**/*.js': [
        'cache-control: public',
        'cache-control: max-age=3156000',
        'cache-control: immutable',
      ],
      '/**/*.css': [
        'cache-control: public',
        'cache-control: max-age=3156000',
        'cache-control: immutable',
      ],
      '/sw.js': [
        'cache-control: public',
        'cache-control: max-age=0',
        'cache-control: must-revalidate',
      ],
    },
  },
},       

Environment

Enter the following command in a terminal and copy/paste its output:

npx envinfo --system --binaries --browsers --npmPackages @netlify/plugin-gatsby

Screenshots

image

Can you submit a pull request?

No (don't know what the problem is)

Pull requests are welcome! If you would like to help us fix this bug, please
check our contributions guidelines.

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.