From c0120dea4292d9b820b2f0a9b8d6f857cc6a05d1 Mon Sep 17 00:00:00 2001 From: George Date: Tue, 20 Feb 2024 13:24:24 -0600 Subject: [PATCH] Fix runtime error caused by knox dependency, mime MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Knox has its own dependency, mime. Knox is no longer maintained and there is an issue with the way it defined its mime dependency in that it did not lock down mime’s version number. Just 2 months ago, mime updated to version 4.0, which no longer supports below Node 14. Our Keystone sites still run on Node 10 so this results in a runtime error (`SyntaxError: Unexpected identifier` on module export syntax) that can’t be worked around. Keystone Classic fixed this by updating to a fork of knox called knox-s3, which specifies a version of mime but is otherwise the same. This commit applies the same fix. Links: https://github.com/Automattic/knox/issues/326 https://github.com/broofa/mime/blob/main/README.md?plain=1#L21 https://github.com/keystonejs/keystone-classic/blob/master/package.json#L63 --- admin/server/api/s3.js | 2 +- fields/types/s3file/S3FileType.js | 4 ++-- package.json | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/admin/server/api/s3.js b/admin/server/api/s3.js index b4009fa62e..12e7051837 100644 --- a/admin/server/api/s3.js +++ b/admin/server/api/s3.js @@ -5,7 +5,7 @@ TODO: Needs Review and Spec module.exports = { upload: function (req, res) { - var knox = require('knox'); + var knox = require('knox-s3'); var keystone = req.keystone; var Types = keystone.Field.Types; diff --git a/fields/types/s3file/S3FileType.js b/fields/types/s3file/S3FileType.js index e38eaee147..90ac8b0222 100644 --- a/fields/types/s3file/S3FileType.js +++ b/fields/types/s3file/S3FileType.js @@ -68,7 +68,7 @@ Object.defineProperty(s3file.prototype, 's3config', { */ s3file.prototype.addToSchema = function (schema) { - var knox = require('knox'); + var knox = require('knox-s3'); var field = this; var paths = this.paths = { @@ -333,7 +333,7 @@ s3file.prototype.generateHeaders = function (item, file, callback) { */ s3file.prototype.uploadFile = function (item, file, update, callback) { - var knox = require('knox'); + var knox = require('knox-s3'); var field = this; var path = field.options.s3path ? field.options.s3path + '/' : ''; var prefix = field.options.datePrefix ? moment().format(field.options.datePrefix) + '-' : ''; diff --git a/package.json b/package.json index c5c4fa65aa..e31c3ed1e7 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "kerberos": "0.0.22", "keystone-storage-namefunctions": "1.1.1", "keystone-utils": "0.4.0", - "knox": "0.9.2", + "knox-s3": "0.9.5", "less-middleware": "2.2.0", "letsencrypt-express": "2.0.6", "list-to-array": "1.1.0",