Breeze / breeze-client

Breeze for JavaScript clients
MIT License
38 stars 16 forks source link

Question #82

Open iz-iznogood opened 3 months ago

iz-iznogood commented 3 months ago

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 breeze-client@2.1.5/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 commented 3 months ago

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 commented 3 months ago

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 breeze-client@2.1.5-mjs? 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 commented 3 months ago

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 commented 5 days ago

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".