tweedegolf / storage-abstraction

Provides an abstraction layer for interacting with a storage; the storage can be local or in the cloud.
MIT License
106 stars 18 forks source link

AdapterLocal file in npm package is missing #58

Closed ueberBrot closed 7 months ago

ueberBrot commented 7 months ago

I use the following package combination:

"@tweedegolf/sab-adapter-amazon-s3": "1.0.12" "@tweedegolf/sab-adapter-local": "1.0.5" "@tweedegolf/storage-abstraction": "2.1.1"

I get the following error message:

Error: Cannot find module '/app/node_modules/.pnpm/@tweedegolf+storage-abstraction@2.1.1/node_modules/@tweedegolf/storage-abstraction/dist/AdapterLocal'
Require stack:
- /app/node_modules/.pnpm/@tweedegolf+storage-abstraction@2.1.1/node_modules/@tweedegolf/storage-abstraction/dist/Storage.js
- /app/node_modules/.pnpm/@tweedegolf+storage-abstraction@2.1.1/node_modules/@tweedegolf/storage-abstraction/dist/index/Storage.js
- /app/main.js
-     at Storage.switchAdapter (/app/node_modules/.pnpm/@tweedegolf+storage-abstraction@2.1.1/node_modules/@tweedegolf/storage-abstraction/dist/Storage.js:64:27)
-     at new Storage (/app/node_modules/.pnpm/@tweedegolf+storage-abstraction@2.1.1/node_modules/@tweedegolf/storage-abstraction/dist/Storage.js:23:14)

The AdapterLocal package is missing in the dist folder as you can see on the npm package index:

image

Additional information:

And the code snippet:

const storage = new Storage({
  type: StorageType.LOCAL,
  directory: '/tmp',
});
ueberBrot commented 7 months ago

I found the issue for my problem. It was an independent issue with Nx. Nx was experiencing problems with the implicit imports of the adapter packages and did not include it in the final build.

I solved the issue by importing them explicitly.

I saw in your code that you're using the AdapterLocal.ts as a fallback, but since it's not in the bundle, this does not work. This should get fixed.

Also question: Is there a specific reason for individual packages for all adapters instead of using the local files in the storage-abstraction package?

abudaan commented 7 months ago

All adapters are separate packages that you have to install explicitly. This way your package will only contain code that it actually needs.

I saw in your code that you're using the AdapterLocal.ts as a fallback, but since it's not in the bundle, this does not work. This should get fixed.

This is intentionally. The fallback to a local file allows you to work on the Storage Abstraction package and all adapter packages in one code base. Only when published to npm the code is split up into (at the moment) 7 separate packages.