Skip to content

Commit

Permalink
Fix runtime error caused by knox dependency, mime
Browse files Browse the repository at this point in the history
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:
Automattic/knox#326
https://github.com/broofa/mime/blob/main/README.md?plain=1#L21
https://github.com/keystonejs/keystone-classic/blob/master/package.json#L63
  • Loading branch information
gwest4 committed Feb 20, 2024
1 parent d0a2740 commit c0120de
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion admin/server/api/s3.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions fields/types/s3file/S3FileType.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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) + '-' : '';
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit c0120de

Please sign in to comment.