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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question #82

Open
iz-iznogood opened this issue Apr 6, 2024 · 4 comments
Open

Question #82

iz-iznogood opened this issue Apr 6, 2024 · 4 comments

Comments

@iz-iznogood
Copy link

iz-iznogood commented Apr 6, 2024

Hello,

i have been using breeze-client package on the server with Sequelize using a custom DataManager class and it worked great.
I try to use it with latest ESM spec and I cannot import the adapters, i get the error

Error [ERR_UNSUPPORTED_DIR_IMPORT]: Directory import 'node_modules\breeze-client\adapter-ajax-fetch' is not supported resolving ES modules imported from system-data\lib\breeze\cBreezeInit.js
Did you mean to import [email protected]/node_modules/breeze-client/bundles/breeze-client-adapter-ajax-fetch.umd.js?

I try to import it like this
import { AjaxFetchAdapter } from "breeze-client/adapter-ajax-fetch";
import { DataServiceWebApiAdapter } from "breeze-client/adapter-data-service-webapi";
import { ModelLibraryBackingStoreAdapter } from "breeze-client/adapter-model-library-backing-store";

Any ideas ? with CommonJS it worked great

I can still do the following but I am looking for a better solution
const require = Module.createRequire(import.meta.url);
require("breeze-client/adapter-ajax-fetch");
require("breeze-client/adapter-data-service-webapi");
require("breeze-client/adapter-model-library-backing-store");

Thanks in advance

@iz-iznogood
Copy link
Author

Just to clarify, the fetch and webapi adapters are not used, the calls are redirected to sequelize internally, but the system needs them otherwise I get startup errors
The model library is needed obviously

@steveschmitt
Copy link
Member

Hmm. Maybe we need a way to detect or specify that Breeze is running in a Sequelize environment, and so doesn't need those other adapters to work.

Regarding the ESM errors, can you try using [email protected]? It's a different build, using ES modules. Someday it will be the default, but right now you have to use the @mjs tag to get it.

@iz-iznogood
Copy link
Author

Hello,

I am indeed using the mjs build.
My code at the moment is augmenting the webapi data service but it can be refractor to a proper class. I will give it a try and share it.
Regarding the import, i am not sure how to fix it, maybe it needs a specific deployment target like node-esm, as it is already implemented for other environments

Thank you

@steveschmitt
Copy link
Member

When we install the cjs build, we get a package.json file in each subpackage (e.g. node_modules/breeze-client/adapter-ajax-fetch/package.json). The package.json file includes the path to the actual js file implementing the subpackage (e.g. ../fesm5/breeze-client-adapter-ajax-fetch.js).

When we install the mjs build, we only get a package.json file in the main package (node_modules/breeze-client/package.json) that contains the paths to all the subpackage definitions and their implementations.

The single package.json approach (of the breeze-client mjs build) works fine unless our application's package.json specifies "type": "module".

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

2 participants