Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update in imports errors #673

Closed
joacub opened this issue Jun 3, 2022 · 5 comments
Closed

Update in imports errors #673

joacub opened this issue Jun 3, 2022 · 5 comments

Comments

@joacub
Copy link

joacub commented Jun 3, 2022

Hi! 馃憢

Firstly, thanks for your work on this project! 馃檪

Today I used patch-package to patch feathers-hooks-common@6.1.1 for the project I'm working on.

Here is the diff that solved my problem:

diff --git a/node_modules/feathers-hooks-common/dist/index.mjs b/node_modules/feathers-hooks-common/dist/index.mjs
index 7ecf617..75118a0 100644
--- a/node_modules/feathers-hooks-common/dist/index.mjs
+++ b/node_modules/feathers-hooks-common/dist/index.mjs
@@ -42,7 +42,9 @@ function actOn(what, ...hooks2) {
 }
 
 // src/hooks/alter-items.ts
-import { BadRequest } from "@feathersjs/errors";
+import errors from "@feathersjs/errors";
+
+const { BadRequest } = errors;
 
 // src/common/pluck.ts
 import _pick from "lodash/pick";
@@ -1134,7 +1136,7 @@ function runHook(context) {
 }
 
 // src/hooks/run-parallel.ts
-import { BadRequest as BadRequest8 } from "@feathersjs/errors";
+const { BadRequest: BadRequest8 } = errors;
 function runParallel(hook, clone, cloneDepth = 6) {
   if (typeof hook !== "function") {
     throw new BadRequest8("Function not provided. (runParallel)");
@@ -1246,7 +1248,7 @@ import _get8 from "lodash/get";
 import _setWith from "lodash/setWith";
 import _clone from "lodash/clone";
 import _debug from "debug";
-import { Forbidden } from "@feathersjs/errors";
+const { Forbidden } = errors;
 var debug3 = _debug("feathers-hooks-common/setField");
 function setField({ as, from, allowUndefined = false }) {
   if (!as || !from) {
@@ -1272,7 +1274,7 @@ function setField({ as, from, allowUndefined = false }) {
 }
 
 // src/hooks/set-now.ts
-import { BadRequest as BadRequest9 } from "@feathersjs/errors";
+const { BadRequest: BadRequest9 } = errors;
 function setNow(...fieldNames) {
   if (!fieldNames.length) {
     throw new BadRequest9("Field name is required. (setNow)");
@@ -1304,7 +1306,8 @@ function setSlug(slug, fieldName) {
 }
 
 // src/hooks/sifter.ts
-import { BadRequest as BadRequest10 } from "@feathersjs/errors";
+const { BadRequest: BadRequest10 } = errors;
+
 function sifter(siftFunc) {
   return (context) => {
     checkContext(context, "after", "find", "sifter");

This issue body was partially generated by patch-package.

@fratzinger
Copy link
Collaborator

Please give more context. How do you use feathers-hooks-common? Do you use js or ts? Do you use commonjs (require()) or esm (import from)? Which node version, etc.?

Which error do you have without this patch?

@soulofmischief
Copy link

soulofmischief commented Jun 8, 2022

I use feathers-hooks-common in a regular ESM package (type: module)

I also experience this error. It is typical of CommonJS modules which do not have proper ESM support.

Important context, running feathers v5.

import { BadRequest } from "@feathersjs/errors";
         ^^^^^^^^^^
SyntaxError: Named export 'BadRequest' not found. The requested module '@feathersjs/errors' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from '@feathersjs/errors';
const { BadRequest } = pkg;

@fratzinger
Copy link
Collaborator

fratzinger commented Jun 9, 2022

I released a fix as v6.1.2. Please try it out and confirm that this solves your problem :)

@fratzinger
Copy link
Collaborator

considering this as fixed. Please contact me, if I'm wrong.

@joacub
Copy link
Author

joacub commented Nov 10, 2022

it does, but now there is another error in the index.mjs esm modules wwhen you import the @feathersks/commons.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants